开发者

Button inside RowDetailsTemplate in DataGrid - how to know which row clicked on?

开发者 https://www.devze.com 2023-03-11 04:38 出处:网络
I have this XAML <DataGrid.RowDetailsTemplate> <DataTemplate> <StackPanel> <Button Content=\"Reply\" Name=\"btnReply\" Click=\"btnReply_Click\" HorizontalAlignment=\"Left\" Margi

I have this 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 bound to List inside btnReply_Click I'd like to get instance of MyObject

Ho开发者_高级运维w do I do this?


var myObject = (sender as FrameworkElement).DataContext as MyObject;

Since the DataContext is inherited.

0

精彩评论

暂无评论...
验证码 换一张
取 消