gpt4 book ai didi

WPF:将 DataGrid 放入 ComboBox

转载 作者:行者123 更新时间:2023-12-04 17:37:08 29 4
gpt4 key购买 nike

在 WPF 中,如何将 DataGrid 放在 ComboBox 中以显示多列?像下面这样的东西似乎没有做任何事情:

<ComboBox>
<ItemsPanelTemplate>
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding customerName}" />
<DataGridTextColumn Binding="{Binding billingAddress}" />
</DataGrid.Columns>
</DataGrid>
</ItemsPanelTemplate>
</ComboBox>

最佳答案

<ComboBox Width="150" Height="30" Name="cb">
<ComboBox.ItemTemplate>
<DataTemplate>
<DataGridRow DataContext="{Binding}" Height="30" Width="150">
<DataGridRow.Template>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="5"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding customerName}" Margin="2"></TextBlock>
<Border BorderBrush="Black" BorderThickness="1" Grid.Column="1" Margin="2"></Border>
<TextBlock Grid.Column="2" Text="{Binding billingAddress}" Margin="2"></TextBlock>
</Grid>

</ControlTemplate>
</DataGridRow.Template>

</DataGridRow>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

关于WPF:将 DataGrid 放入 ComboBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14950925/

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