gpt4 book ai didi

wpf - 如何将复选框项目拉伸(stretch)到组合框的整个宽度

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

我有一个带有复选框项目的乘法组合框

<ComboBox  x:Name="cmb" IsEditable="True"  IsReadOnly="True" DropDownClosed="cmb_DropDownClosed">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Content="{Binding NmColumn }" HorizontalAlignment="Stretch"
IsChecked="{Binding Path=bChecked, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Tag="{Binding IdColumn}"
/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

当我点击复选框时,一切都很好。但是如果复选框宽度小于组合框的宽度,当我单击复选框的右侧时,组合框会关闭。如何覆盖这种行为?

最佳答案

设置 HorizontalContentAlignmentStretchComboBox.ItemContainerStyle :

<ComboBox  x:Name="cmb" IsEditable="True"  IsReadOnly="True" DropDownClosed="cmb_DropDownClosed">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<CheckBox Content="{Binding NmColumn }" HorizontalAlignment="Stretch"
IsChecked="{Binding Path=bChecked, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Tag="{Binding IdColumn}"
/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>

关于wpf - 如何将复选框项目拉伸(stretch)到组合框的整个宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42291111/

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