【问题标题】:Button inside RowDetailsTemplate in DataGrid - how to know which row clicked on?DataGrid 中 RowDetailsTemplate 内的按钮 - 如何知道点击了哪一行?
【发布时间】:2011-06-08 22:11:05
【问题描述】:

我有这个 XAML

<DataGrid.RowDetailsTemplate>
    <DataTemplate>
        <StackPanel>
            <Button Content="Reply" Name="btnReply" Click="btnReply_Click" HorizontalAlignment="Left" Margin="5" Padding="10,0" />
            <Label Content="{Binding Path=Subject}" FontWeight="Bold" />
            <Label Content="{Binding Path=Body}" />
        </StackPanel>
    </DataTemplate>
</DataGrid.RowDetailsTemplate>

DataGrid 绑定到 List 在 btnReply_Click 里面我想获取 MyObject 的实例

我该怎么做?

【问题讨论】:

    标签: c# wpf xaml data-binding datagrid


    【解决方案1】:
    var myObject = (sender as FrameworkElement).DataContext as MyObject;
    

    因为继承了DataContext。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-31
      • 2017-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多