0
給定帶有切換行詳細信息按鈕的DataGrid。爲什麼每當財產被更改時都會摺疊細節?如何在屬性更改時停止DataGrid摺疊RowDetails?
它摺疊細節每當列使用:
UpdateSourceTrigger=LostFocus
而且它縮短了它每當在詳細視圖中的屬性被更新。
有沒有辦法讓它打開?該行仍處於選中狀態。
XAML:
RowDetailsVisibilityMode="Collapsed"
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="buttonDetails" Content="Hello" ButtonBase.Click="Details_Click"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
C#:
// Load stuff from db
_context.JobCollection.Load();
// Set source with db stuff
jobViewSource.Source = _context.JobCollection.Local;
private void Details_Click(object sender, RoutedEventArgs e)
{
try
{
// the original source is what was clicked. For example
// a button.
DependencyObject dep = (DependencyObject)e.OriginalSource;
// iteratively traverse the visual tree upwards looking for
// the clicked row.
while ((dep != null) && !(dep is DataGridRow))
{
dep = VisualTreeHelper.GetParent(dep);
}
// if we found the clicked row
if (dep != null && dep is DataGridRow)
{
// get the row
DataGridRow row = (DataGridRow)dep;
// change the details visibility
if (row.DetailsVisibility == Visibility.Collapsed)
{
row.DetailsVisibility = Visibility.Visible;
}
else
{
row.DetailsVisibility = Visibility.Collapsed;
}
}
}
catch (System.Exception)
{
}
}
已經有這個。不回答這個問題。不管怎麼說,還是要謝謝你。 – flux
發佈您的XAML代碼。或者在Dropbox上發佈你的代碼並在評論中發佈鏈接。 – AnjumSKhan
@flux我已經完全按照你所描述的做了一個示例應用程序。 – AnjumSKhan