如何在 winrt 中通过 VisualState 更改 ListView 项的 DataTemplate?
how change DataTemplate of ListView Item by VisualState in winrt?
我在点击编辑时尝试 TextBlock
将 listViewItem
的 DataTemplate
更改为 VisualState
,但对我来说没有变化
我的观点
<Page
................
DataContext="{Binding Categories, Source={StaticResource Locator}}"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<DataTemplate x:Key="Template">
<local:MyTemplate Width="393"/>
</DataTemplate>
</Page.Resources>
<Grid x:Name="Layout">
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding EditText}" Margin="10" FontSize="25" HorizontalAlignment="Right" VerticalAlignment="Center">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding EditCommand}"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</TextBlock>
<ListView Grid.Row="1"
ItemsSource="{Binding AllCategories}"
ItemTemplate="{StaticResource Template}"
SelectionMode="Single"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
</ListView>
</Grid>
和我的用户控件
<UserControl>
...................................
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="TamplateState">
<VisualState x:Name="EditeState">
<Storyboard>
........................................................
</Storyboard>
</VisualState>
<VisualState x:Name="Default"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<i:Interaction.Behaviors>
<core:DataTriggerBehavior Binding="{Binding IsEdit}" Value="True">
<core:GoToStateAction StateName="EditeState"/>
</core:DataTriggerBehavior>
<core:DataTriggerBehavior Binding="{Binding IsEdit}" Value="False">
<core:GoToStateAction StateName="Default"/>
</core:DataTriggerBehavior>
</i:Interaction.Behaviors>
</Grid>
IsEdit
在 viewMoedl 中是布尔值 属性。
我被 belend 修复了
<i:Interaction.Behaviors>
<core:DataTriggerBehavior x:Name="dataTriggerBehavior" Binding="{Binding Main.IsEdit, Source={StaticResource Locator}}" Value="True">
<core:GoToStateAction StateName="EditeState"/>
</core:DataTriggerBehavior>
<core:DataTriggerBehavior Binding="{Binding Main.IsEdit, Source={StaticResource Locator}}" Value="False">
<core:GoToStateAction StateName="Default"/>
</core:DataTriggerBehavior>
</i:Interaction.Behaviors>
</Grid>
我在点击编辑时尝试 TextBlock
将 listViewItem
的 DataTemplate
更改为 VisualState
,但对我来说没有变化
我的观点
<Page
................
DataContext="{Binding Categories, Source={StaticResource Locator}}"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<DataTemplate x:Key="Template">
<local:MyTemplate Width="393"/>
</DataTemplate>
</Page.Resources>
<Grid x:Name="Layout">
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding EditText}" Margin="10" FontSize="25" HorizontalAlignment="Right" VerticalAlignment="Center">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding EditCommand}"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</TextBlock>
<ListView Grid.Row="1"
ItemsSource="{Binding AllCategories}"
ItemTemplate="{StaticResource Template}"
SelectionMode="Single"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
</ListView>
</Grid>
和我的用户控件
<UserControl>
...................................
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="TamplateState">
<VisualState x:Name="EditeState">
<Storyboard>
........................................................
</Storyboard>
</VisualState>
<VisualState x:Name="Default"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<i:Interaction.Behaviors>
<core:DataTriggerBehavior Binding="{Binding IsEdit}" Value="True">
<core:GoToStateAction StateName="EditeState"/>
</core:DataTriggerBehavior>
<core:DataTriggerBehavior Binding="{Binding IsEdit}" Value="False">
<core:GoToStateAction StateName="Default"/>
</core:DataTriggerBehavior>
</i:Interaction.Behaviors>
</Grid>
IsEdit
在 viewMoedl 中是布尔值 属性。
我被 belend 修复了
<i:Interaction.Behaviors>
<core:DataTriggerBehavior x:Name="dataTriggerBehavior" Binding="{Binding Main.IsEdit, Source={StaticResource Locator}}" Value="True">
<core:GoToStateAction StateName="EditeState"/>
</core:DataTriggerBehavior>
<core:DataTriggerBehavior Binding="{Binding Main.IsEdit, Source={StaticResource Locator}}" Value="False">
<core:GoToStateAction StateName="Default"/>
</core:DataTriggerBehavior>
</i:Interaction.Behaviors>
</Grid>