[英]WPF: Show Context Menu when Only one cell is selected
What is wrong with this code? 此代码有什么问题?
The DataTrigger on SelectedCells.Count is not firing up. SelectedCells.Count上的DataTrigger没有启动。
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Exclude.Exclude,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="True">
<Setter Property="Background" Value="#FFEBEBEB"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SelectedCells.Count,ElementName=dgAssets }" Value="1">
<Setter Property="ContextMenu" Value="{StaticResource RowMenu}" />
<Setter Property="Background" Value="Green"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
Trying to show the context menu , only when just a single cell is selected. 尝试显示上下文菜单,仅当仅选择一个单元格时。
The SelectedCells
property of a DataGrid
returns an internal object called SelectedCellsCollection
. DataGrid
的SelectedCells
属性返回一个称为SelectedCellsCollection
的内部对象。 It extends another class called VirtualizedCellInfoCollection . 它扩展了另一个名为VirtualizedCellInfoCollection的类。 It does not implement neither
INotifyCollectionChanged
nor INotifyPropertyChanged
interfaces. 它既不实现
INotifyCollectionChanged
也不实现INotifyPropertyChanged
接口。 Moreover its Count
property is not a dependecy property. 此外,其
Count
属性不是依赖属性。
So your binding is not able to notify to your data trigger when the number of selected cells increases or decreases. 因此,当选定单元格的数量增加或减少时,绑定将无法通知数据触发器。 For the data trigger its value is always 0.
对于数据触发器,其值始终为0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.