如何在winrt中通过VisualState更改ListView项的DataTemplate?

时间:2015-07-27 19:50:07

标签: xaml windows-runtime windows-phone-8.1 listviewitem visualstates

点按“我需要修改TextBlock DataTemplate更改listViewItem 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

<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中的布尔属性。

1 个答案:

答案 0 :(得分:0)

由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>