我有一个datagrid
,其中第一列对于所有行都是常量。
我想跟随以下行为:
action A
知道选择了哪一行。这是基于事件的(触发事件)。action B
知道选择了哪一行。为此,我写了以下代码:
<DataGrid x:Name="dataGrid" ItemsSource="{Binding source}" MouseDoubleClick="doubleClick">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="♣" Foreground="{Binding Path=color}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding FirstCellCommand}" CommandParameter="{Binding SelectedItem, ElementName=dataGrid}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Label" Binding="{Binding label, UpdateSourceTrigger=PropertyChanged}"/>
</DataGrid.Columns>
</DataGrid>
点(1.)工作正常,但(2.)不会触发操作。
我在这里错过了一点吗?
答案 0 :(得分:0)
万一有人会有类似的问题:我还没找到我想要的东西!但是有一个使用代码隐藏的工作。 它对我有用,如下:
@Override
protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) {
services.put(FetchingService.class.getName(), asService(new FetchServiceImpl(), null));
}
我删除了<DataGrid x:Name="dataGrid" ItemsSource="{Binding source}" MouseDoubleClick="doubleClick">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="♣" Foreground="{Binding Path=color}" MouseDown="this_MouseDown"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Label" Binding="{Binding label, UpdateSourceTrigger=PropertyChanged}"/>
</DataGrid.Columns>
</DataGrid>
并将Interaction.Triggers
添加到MouseDown
。
如果有人使用绑定提供答案,我将不胜感激。