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

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

问题描述

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

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?

推荐答案

ComboBox.ItemContainerStyle中将Horizo​​ntalContentAlignment设置为Stretch:

<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天全站免登陆