gpt4 book ai didi

wpf - 我需要对RowDetailsTemplate进行扩展/折叠

转载 作者:行者123 更新时间:2023-12-03 20:06:32 30 4
gpt4 key购买 nike

我有一个DataGrid。它具有DataGrid.RowDetailsTemplate。当单击一个按钮时,它应该展开/折叠;我该怎么做?

<Custom:DataGrid RowDetailsVisibilityMode="VisibleWhenSelected" SelectionMode="Extended" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserSortColumns="False">
<Custom:DataGrid.RowDetailsTemplate>
<DataTemplate>
<Custom:DataGrid>
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Binding="{Binding idClient, Mode=Default}" Header="Ид" IsReadOnly="True"/>
<Custom:DataGridTextColumn Binding="{Binding name_client, Mode=Default}" Header="Имя" IsReadOnly="True"/>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
</DataTemplate>
</Custom:DataGrid.RowDetailsTemplate>
<Custom:DataGrid.Columns>
<Custom:DataGridTemplateColumn>
<Custom:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Expander IsExpanded="True"/>
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
</Custom:DataGridTemplateColumn>
<Custom:DataGridTextColumn Binding="{Binding idPartner, Mode=Default}" Header="Ид" IsReadOnly="True"/>
<Custom:DataGridTextColumn Binding="{Binding name_partner, Mode=Default}" Header="Имя" IsReadOnly="True"/>
</Custom:DataGrid.Columns>
</Custom:DataGrid>

最佳答案

检查这个...


Adding a Button to a WPF DataGrid


要么

XAML:

<DataGrid Name="dg1" AutoGenerateColumns="False" SelectionMode="Single" CanUserAddRows="false" CanUserDeleteRows="False" SelectionUnit="FullRow" >
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="0"/>
</Style>
</DataGrid.CellStyle>

<DataGrid.RowHeaderTemplate>
<DataTemplate>
<Expander Expanded="Expander_Expanded" Collapsed="Expander_Collapsed">

</Expander>
</DataTemplate>
</DataGrid.RowHeaderTemplate>

<DataGrid.Columns>
<DataGridTextColumn Header="Name" IsReadOnly="True" Width="100" Binding="{Binding Name}" />
<DataGridTextColumn Header="Title" IsReadOnly="True" Width="100" Binding="{Binding Title}" />
<DataGridTextColumn Header="Job" IsReadOnly="True" Width="100" Binding="{Binding Job}" />
</DataGrid.Columns>

<DataGrid.RowDetailsTemplate>
<DataTemplate>
<TextBlock Text="{Binding Isi, Converter={StaticResource ResourceKey=isiTextConverter}}" Margin="10,5,0,0" />
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>


MainWindow.xaml.cs

private void Expander_Expanded(object sender, RoutedEventArgs e)
{
for (var vis = sender as Visual; vis != null; vis = VisualTreeHelper.GetParent(vis) as Visual)
if (vis is DataGridRow)
{
var row = (DataGridRow)vis;
row.DetailsVisibility = row.DetailsVisibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
break;
}
}

private void Expander_Collapsed(object sender, RoutedEventArgs e)
{
for (var vis = sender as Visual; vis != null; vis = VisualTreeHelper.GetParent(vis) as Visual)
if (vis is DataGridRow)
{
var row = (DataGridRow)vis;
row.DetailsVisibility = row.DetailsVisibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
break;
}
}


输出量

关于wpf - 我需要对RowDetailsTemplate进行扩展/折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3829137/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com