绑定后单击DataGrid中的列

时间:2013-02-11 06:23:17

标签: wpf datagrid

我有以下DataGrid:

<DataGrid SelectedItem="{Binding CurrentX}" ColumnWidth="*" ItemsSource="{Binding Model.Xlist, Mode=TwoWay}" AutoGenerateColumns="False">
        <DataGrid.Columns>
      <DataGridTemplateColumn Width="Auto" Header="GO">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Image Width="30" Height="30" Source="../Resources/xx.ico" MouseDown="Image_MouseDown">
                        </Image>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
</DataGrid>

当我点击一行时,点击发生在绑定到SelectedItem之前,我希望它以相反的方式(首先是绑定,然后是点击事件),

可以这样做吗?

1 个答案:

答案 0 :(得分:1)

我有类似的问题。使用MouseUp事件:

<my:DataGridTemplateColumn Width="18" CanUserResize="False">
    <my:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Image Width="16" Style="{StaticResource ImageStyle}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="MouseUp">
                        <cmd:EventToCommand Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ShowErrorMessageCommand}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Image>
        </DataTemplate>
    </my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>