我有这个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的实例
我该怎么做?
答案 0 :(得分:1)
var myObject = (sender as FrameworkElement).DataContext as MyObject;
由于DataContext是继承的。