gpt4 book ai didi

wpf - 如何在数据网格中显示多个 ListView

转载 作者:行者123 更新时间:2023-12-04 19:39:31 24 4
gpt4 key购买 nike

在我的程序中,我目前有一个数据网格,其中包含一个显示 ListView 的修改后的行模板。因此,当用户在数据网格中选择一行时,该行会展开并显示 ListView ,而当用户选择不同的行时,原始列表会折叠,新行的列表会展开。我现在被要求让它允许扩展多个 ListView ,但我不确定如何做到这一点。

我的 xaml 代码:

<DataGrid ItemsSource="{Binding Path=Accounts}" SelectedItem="{Binding Path=SelectedAccount}" AutoGenerateColumns="False"
CanUserAddRows="False" CanUserDeleteRows="False" Width="Auto">
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<ListView MaxHeight="200" ItemsSource="{Binding Path=DataContext.SelectedAccount.Details, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"
SelectedItem="{Binding Path=DataContext.SelectedDetail, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"
Tools:GridViewSort.AutoSort="True" >
<ListView.View>
<GridView>
<GridViewColumn Header="Account" DisplayMemberBinding="{Binding Path=AccountCode}"
Tools:GridViewSort.PropertyName="AccountCode" Width="Auto" />

<GridViewColumn Header="Description" DisplayMemberBinding="{Binding Path=Description}"
Tools:GridViewSort.PropertyName="Description" Width="Auto"/>
</GridView>
</ListView.View>
<ListView.Style>
<Style TargetType="ListView">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=DataContext.SelectedAccount.Details.Count, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" Value="0">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.Style>
</ListView>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
<DataGrid.Columns>
<DataGridTextColumn Header="Account" Binding="{Binding Path=AccountCode}"/>
<DataGridTextColumn Header="Title" Binding="{Binding Path=AccountTitle}" />
</DataGrid.Columns>
</DataGrid>

所以我在我的数据网格中显示了一个帐户列表,并且在每个帐户上都有一个详细信息列表,该列表显示在选择帐户时出现的 ListView 中。 How can i keep the details from the originally selected account in the listview visible when other accounts are selected?

最佳答案

如果你想让之前选中行的 detailsTemplate 保持可见,你可以这样尝试。您订阅 DataGrid 的 RowDetailsVisibilityChanged 事件

<DataGrid  RowDetailsVisibilityChanged="DataGrid_RowDetailsVisibilityChanged_1">
.......
........
</DataGrid>

private void DataGrid_RowDetailsVisibilityChanged_1(object sender, DataGridRowDetailsEventArgs e)
{
e.Row.DetailsVisibility= Visibility.Visible;
}

希望对您有所帮助。

关于wpf - 如何在数据网格中显示多个 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18337009/

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