Sunday 15 February 2015

windows - Change template of list item in WinRT app based on selection state -


I try to change the display of ListViewItem in a WinRT app based on the selection of that item. In WPF, I would have used a style trigger, but it is not available in WinRT. So after searching the web for some time, I think I should use Visual State Manager. As I have understood, in the ListView there is a visual state group "Selection Stats", in which the states I am interested in have been included. So I came up with the following ItemContainerStyle which I apply to my ListView:

  & lt; Style x: key = "itemcontain style" target type = "selector item" & gt; & Lt; Setter Estates = "Template" & gt; & Lt; Setter.Value & gt; & Lt; ControlTemplate TargetType = "SelectorItem" & gt; & Lt; Grid & gt; & Lt; TextBlock x: name = "text block" text = "{binding}" visibility = "visible" /> & Lt; Text Box X: Name = "Text Box" Text = "{Binding Path = Name, Mode = Two}" Visibility = "Brief" /> & Lt; VisualStateManager.VisualStateGroups & gt; & Lt; Visualstate group x: name = "selectionstates" & gt; & Lt; VisualState X: Name = "unselected" /> & Lt; VisualState X: Name = "Selected" & gt; & Lt; Storyboard & gt; & Lt; ObjectAnimationUsingKeyFrames Storyboard. TargetName = "textbox" storyboard TargetProperty = "Visibility" & gt; & Lt; DiscreteObjectKeyFrame Keytime = "0" value = "visible" /> & Lt; / ObjectAnimationUsingKeyFrames & gt; & Lt; ObjectAnimationUsingKeyFrames Storyboard. TargetName = "textBlock" storyboard. TargetProperty = "Visibility" & gt; & Lt; DiscreteObjectKeyFrame Keytime = "0" value = "abbreviated" /> & Lt; / ObjectAnimationUsingKeyFrames & gt; & Lt; / Storyboard & gt; & Lt; / VisualState & gt; & Lt; / VisualStateGroup & gt; & Lt; /VisualStateManager.VisualStateGroups> & Lt; / Grid & gt; & Lt; / ControlTemplate & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt;   

Appears as expected in the normal item (so I think my style is implemented), but selection material does not work at all. Why? I think states are started automatically, right? So how can I fix it?

Note: I use "selector item" as the target type because I want to use the same style on grid view, is this the problem? Changing to "ListViewItem" did not resolve my problem ...

Thanks in advance, Christophe

You can use (UIElement.Visibility) as the value of property as the value of DiscreteObjectKeyFrame as the the wanted. & lt; VisualState X: Name = "Selected" & gt; & Lt; Storyboard & gt; & Lt; ObjectAnimationUsingKeyFrames Storyboard. TargetName = "textbox" storyboard TargetProperty = "(UIElement.Visibility)" & gt; & Lt; DiscreteObjectKeyFrame Keytime = "0" value = "visible" /> & Lt; / ObjectAnimationUsingKeyFrames & gt; & Lt; ObjectAnimationUsingKeyFrames Storyboard. TargetName = "textBlock" storyboard. TargetProperty = "(UIElement.Visibility)" & gt; & Lt; DiscreteObjectKeyFrame Keytime = "0" value = "abbreviated" /> & Lt; / ObjectAnimationUsingKeyFrames & gt; & Lt; / Storyboard & gt; & Lt; / VisualState & gt;

No comments:

Post a Comment