【发布时间】:2020-02-21 13:16:40
【问题描述】:
我有一个包含颜色列表的列表框控件。这是代码和图片:
<ListBox Name="FillSelections" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Center" SelectedItem="{Binding SelectedColor}" SelectionMode="Single" Style="{StaticResource HorizontalListBoxStyle}" ItemsSource="{Binding FillColors}" ItemTemplate="{StaticResource ColorsItemTemplate}"></ListBox>
<DataTemplate x:Key="ColorsItemTemplate">
<Border BorderBrush="Transparent">
<Rectangle Width="20" StrokeThickness="1" Stroke="Black">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding}" />
</Rectangle.Fill>
</Rectangle>
</Border>
图片:
我怎样才能改变最后一项的样式,就像这样:
【问题讨论】:
-
您也许可以使用基于
RelativeSource PreviousData的触发器,例如this answer -
如果这么简单,我就不会在这里问了。他/她需要先验证,而不是给予减分票(给我的人 - 点)。我的列表框项目不是静态的。这取决于我的应用程序的肤色,并显示该肤色的所有差异阴影。
-
而不是 Binding="{Binding RelativeSource={RelativeSource PreviousData }}",有什么方法可以与当前数据进行比较。我尝试了自我但没有工作。
标签: wpf listbox itemtemplate