Reputation: 153
I have a ListView that looks like this:
<ListView x:Name="MyList" ItemsSource="{Binding Path=MyItems}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="Title" Text="{Binding Path=TitleCategory}"/>
<TextBlock x:Name="Body" Text="{Binding Path=BodySummary}" Style="{StaticResource BodyTextStyle}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The BodyTextStyle I apply to that TextBlock sets the width at 600px, and everything displays fine in FullScreenLandscape. However, when I switch into SnappedView, the text clips off due to the decreased screen width. Normally I'd set the width like so:
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="Body">
<DiscreteObjectKeyFrame KeyTime="0" Value="300"/>
</ObjectAnimationUsingKeyFrames>
But this produces a runtime crash, I assume because the item(s) I'm referencing are in an ItemTemplate. What is the correct way to change the width of every item in my ListView when I go into SnappedView?
Upvotes: 0
Views: 480
Reputation: 31724
From what I have seen in the samples and templates the recommended way seems to be to provide a separate ListView for the different view state and after trying to optimize it by trying to do something similar to what you are doing and having to fight a lot of issues I've decided to give up and do what the templates do. Save yourself the trouble and use a separate ListView for the snapped view and simply switch visibilities of both ListViews when the view state changes.
Also I would assume that you are right and the problem comes from the name scope issue with templates having separate name scopes.
Upvotes: 1