Changing Control Properties in ItemTemplate in VisualStateManager (WinRT XAML)

I have a ListView that I use for my view, SnapView and Portrait. However, I would like to modify some elements of my element template in both of these views. VisualStateManager seems like the perfect place for this, but I can't figure it out.

Here is my ListView XAML:

<ListView x:Name="SampleListView" ItemsSource="{Binding Samples}" Visibility="Collapsed"> <ListView.ItemTemplate> <DataTemplate> <local:SampleBlock SampleText="{Binding ElementName=pageRoot, Path=DataContext.SampleText, Mode=TwoWay}" Height="70" Width="Auto" Margin="5" /> </DataTemplate> </ListView.ItemTemplate> </ListView> 

I want to change the Height and Margin of the SampleBlock control using the VisualStateManager page. Here is my visual state manager that shows and hides my ListView:

 <VisualState x:Name="FullScreenPortrait"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SampleListView" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SampleGridView" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Snapped"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SampleListView" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SampleGridView" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> 

Is there a way to access the element template on the VisualStateManager page, or should I attack this from a different angle?

+4
source share
1 answer

You cannot change the properties of the DataTemplate, but you can change the actual ItemTemplate in the ListView to the specific template that will be used for the bound view

 <VisualState x:Name="Snapped"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="itemListView" Storyboard.TargetProperty="ItemTemplate"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedListViewItemTemplate}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> 
+9
source

All Articles