如何将复选框项拉伸到组合框的整个宽度 [英] How to stretch checkbox item the full width of the combobox

查看:90
本文介绍了如何将复选框项拉伸到组合框的整个宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a multiply combobox with checkbox items

<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>

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

When I click on checkbox all is well. But if the checkbox width less than the width of combobox, when I click to the right of the checkbox, the combobox closes. how to override this behavior?

推荐答案

Horizo​​ntalContentAlignment 设置为 Stretch ComboBox.ItemContainerStyle 中的code>:

Set HorizontalContentAlignment to Stretch in ComboBox.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>

这篇关于如何将复选框项拉伸到组合框的整个宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆