我有一个DataGrid,它的RowDetails设置为在选择时显示(RowDetailsVisibilityMode="VisibleWhenSelected")。现在我想要能够摆脱它!我在行细节上放置了一个关闭按钮,并使用此代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
e.Handled = true;
Button button = sender as Button;
DataGridRow row = button.FindAncestor<DataGridRow>();
row.DetailsVisibility = Visibility.Collapsed;
}
这段代码让我完成了90%的工作,但是一旦某一行的详细信息被折叠,下次选中该行时就不会再出现。