xamlwindows-runtimewindows-phone-8.1listviewitemvisualstates

how change DataTemplate of ListView Item by VisualState in winrt?


I Try When Tap Edit TextBlock change the DataTemplate of listViewItem by VisualState but does not change for me

my View

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

and my 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 is boolean property in viewMoedl.


Solution

  • i fixed by 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>