【发布时间】:2013-08-08 06:25:34
【问题描述】:
我有以下 DataGrid 定义
<DataGrid
VirtualizingPanel.VirtualizationMode="Recycling"
CanUserAddRows="False"
CanUserDeleteRows="False"
SelectionMode="Single"
ItemsSource="{Binding
ToolPath.ToolPath,
Mode=OneWay,
Converter={StaticResource indexedConverter}}"
AutoGenerateColumns="False"
SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}">
我正在使用 MVVM,并且有一个带有 SelectedIndex 属性的视图模型来实现 INPC。我使用 snoop 来验证 DataGrid 上的 SelectedIndex 在视图模型中发生变化时是否发生了变化。但是,当我这样做时,不会选择或突出显示网格的行。
如您所见,该行未突出显示,但我想我可以检测到该行左侧的 3 像素宽小部件是深蓝色。
是否有 XAML only 方式 via databinding ( without writing code behind ) 让行选择工作?
【问题讨论】:
-
你能粘贴IndexedConverter的代码吗?为什么不只是绑定到集合并使用 SelectedItem?