的ListViewItem的風格着扳機未選定,但可以觸發選擇。的ListViewItem的風格着扳機未選擇
我想看到的東西表明,當選擇的ListView項藏時未選擇。
但我可以看到它被顯示,但無法看到它被隱藏。
我複製樣式從https://msdn.microsoft.com/en-us/library/windows/apps/mt299136.aspx
而且我確信我將SelectionMode是單身。
,我從複製的代碼是
<Style x:Key="ListViewItemStyle" TargetType="ListViewItem">
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
<Setter Property="Background" Value="{ThemeResource ListViewItemBackground}"/>
<Setter Property="Foreground" Value="{ThemeResource ListViewItemForeground}"/>
<Setter Property="TabNavigation" Value="Local"/>
<Setter Property="IsHoldingEnabled" Value="True"/>
<Setter Property="Padding" Value="12,0,12,0"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}"/>
<Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}"/>
<Setter Property="AllowDrop" Value="False"/>
<Setter Property="UseSystemFocusVisuals" Value="True"/>
<Setter Property="FocusVisualMargin" Value="0"/>
<Setter Property="FocusVisualPrimaryBrush" Value="{ThemeResource ListViewItemFocusVisualPrimaryBrush}"/>
<Setter Property="FocusVisualPrimaryThickness" Value="2"/>
<Setter Property="FocusVisualSecondaryBrush" Value="{ThemeResource ListViewItemFocusVisualSecondaryBrush}"/>
<Setter Property="FocusVisualSecondaryThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Grid>
<ContentPresenter ></ContentPresenter>
<Button x:Name="b" Opacity="0"></Button>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselecting">
<Storyboard BeginTime="0:0:0">
<DoubleAnimation Storyboard.TargetName="b"
Storyboard.TargetProperty="Opacity"
Duration="0:0:0.1"
To="0" />
</Storyboard>
</VisualState>
<VisualState x:Name="Unselected">
<Storyboard BeginTime="0:0:0">
<DoubleAnimation Storyboard.TargetName="b"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="0" />
</Storyboard>
</VisualState>
<VisualState x:Name="Selected">
<Storyboard BeginTime="0:0:0">
<DoubleAnimation Storyboard.TargetName="b"
Storyboard.TargetProperty="Opacity"
Duration="0"
To="1" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我看到這個答案https://stackoverflow.com/a/36010296/6116637這阿奇納提供使用CustomUnselected和的SelectionChanged時改變它的方法。
這是一個很好的方式,但我不想寫相同的代碼來很多地方,我還有很多的ListView應該做的it.Are有沒有什麼好的辦法做到這一點只寫XAML?
我已經看到,說結合IsSelected答案,但不能做它的TemplateBinding,當我想能見度爲TemplateBinding不能使用轉換。
而當我使用Visibility="{Binding Path={TemplateBinding IsSelected},Converter={StaticResource BooleanVisibility},Mode=OneWay}"
或Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected,Converter={StaticResource BooleanInverseVisibility},Mode=OneWay}"
,結果不是我想要的。
參見:https://stackoverflow.com/a/40328520/6116637
我也看到https://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj709921.aspx?f=255&MSPPError=-2147217396 – lindexi
見http://stackoverflow.com/questions/40327901/how-to-bind-isselected-property-in-datatemplate-of-listviewitem我不想將它綁定到IsSelected。 – lindexi
你可以發佈數據模板代碼嗎?你能告訴你想要展示什麼嗎? – Archana