所以我在 a中设置了Template
属性,并尝试绑定到其中的非属性,它起作用了!Setter
Style
ListViewItem
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border Background="{DynamicResource TransparentBrush}" BorderBrush="{DynamicResource TransparentBrush}" BorderThickness="1" CornerRadius="2" Height="Auto" HorizontalAlignment="Stretch" Name="border" VerticalAlignment="Stretch">
<Border Background="{DynamicResource TransparentBrush}" BorderBrush="{DynamicResource TransparentBrush}" BorderThickness="1" CornerRadius="2" Height="Auto" Name="border1">
<TextBlock Text="{Binding Path=FileName}" TextAlignment="Center" TextTrimming="CharacterEllipsis" Width="Auto" />
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Border.BorderBrush" TargetName="border" Value="{DynamicResource ButtonPressedOuterBorderBrush}" />
<Setter Property="Border.Background" TargetName="border" Value="{DynamicResource ButtonPressedOuterBackgroundBrush}" />
<Setter Property="Border.Background" TargetName="border1" Value="{DynamicResource ButtonPressedInnerBackgroundBrush}" />
<Setter Property="Border.BorderBrush" TargetName="border1" Value="{DynamicResource ButtonPressedInnerBorderBrush}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="UIElement.IsMouseOver" Value="True" />
<Condition Property="IsSelected" Value="False" />
<Condition Property="UIElement.IsEnabled" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Border.BorderBrush" TargetName="border1" Value="{DynamicResource ButtonHoverInnerBorderBrush}" />
<Setter Property="Border.Background" TargetName="border1" Value="{DynamicResource ButtonHoverInnerBackgroundBrush}" />
<Setter Property="Border.Background" TargetName="border" Value="{DynamicResource ButtonHoverOuterBackgroundBrush}" />
<Setter Property="Border.BorderBrush" TargetName="border" Value="{DynamicResource ButtonHoverOuterBorderBrush}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="UIElement.IsKeyboardFocusWithin" Value="True" />
<Condition Property="IsSelected" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Border.BorderBrush" TargetName="border1" Value="{DynamicResource ButtonHoverInnerBorderBrush}" />
<Setter Property="Border.Background" TargetName="border1" Value="{DynamicResource ButtonHoverInnerBackgroundBrush}" />
<Setter Property="Border.Background" TargetName="border" Value="{DynamicResource ButtonHoverOuterBackgroundBrush}" />
<Setter Property="Border.BorderBrush" TargetName="border" Value="{DynamicResource ButtonHoverOuterBorderBrush}" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
在这里,该属性FileName
(显然)不是 ListViewItem 的一部分,它是我放入ListView
. 它在第 6 行。
对于那些想要这个主题的人,它就在那里,在ControlTemplate.Triggers
!
对于我使用的资源(画笔),您需要Fluent。我从Fluent.Button
.
只需用您的数据模板替换 TextBlock 就可以了!:)