什么会导致WPF ComboBox的MaxDropDownHeight根据绑定数据被忽略? [英] What can cause a WPF ComboBox's MaxDropDownHeight to be ignored based on bound data?

查看:136
本文介绍了什么会导致WPF ComboBox的MaxDropDownHeight根据绑定数据被忽略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个ComboBoxHelper类,该类注册了一个附加属性,以在您单击它时调整下拉列表的高度.这可行,但是看来我需要绑定到的ObservableCollection,它将忽略MaxDropDownHeight,但是如果 我将其更改为另一个,这是我在附加属性中设置的长度.这两个列表都足够长以容纳设置的大小,如果忽略设置的大小,则大约为5个项目.

I have this ComboBoxHelper class that registered an attached property to resize the height of the drop down list when you click on it. This works, but it appears that the ObservableCollection I need to bind to, it will ignore the MaxDropDownHeight, but if I change it to another one, it is the length I set in the attached property. Both lists are long enough to accommodate the set size, when it ignores it, it's approximately 5 items tall.

是否有任何可能通过更改绑定数据而在同一控件上导致此错误?

Is there anything that could cause this on the same control just by changing out the bound data?

我正在调试,发现绑定到组合框似乎忽略了MaxDropDownHeight的集合时,对传递的组合框的引用反映了列表中的0个项目,我什至使动作异步并等待最多2秒, 即使我清楚地看到列表中的项目,也没有报告.它认为它是空的,这一定是为什么它不允许指定的高度,但是我在这里很茫然.

I was debugging and found that when bound to the collection that the combo box seems to ignore the MaxDropDownHeight, the reference to the combo box that is passed reflects 0 items in the list, I've even made the action async and waited up to 2 seconds and even though I clearly see the items in the list, it reports none. It thinking it's empty must be why it's not allowing the specified height, but I'm at a loss here.

推荐答案

我不知道您的代码在做什么,但我认为这是问题所在.

I don't know what your code is doing but I think it's however you're setting MaxDropDownHeight is the problem.

绑定绑定不会导致MaxDropDownHeight无法正常工作.

There is nothing inherent about binding a collection that will stop MaxDropDownHeight from working.

我尝试了绑定集合,并在标记中设置了MaxDropDownHeight,我尝试了绑定MaxDropDownHeight 一切似乎都很好.

I tried with a bound collection and setting MaxDropDownHeight in markup, I tried binding MaxDropDownHeight  and it all seems to work fine.

我的示例代码基于另一个答案,但我的视图模型是

My sample code is based on another answer but my viewmodel:

    public class MainWindowViewModel :ViewModelBase
    {
        public double MaxDropDownHeight { get; set; } = 50;
        public ObservableCollection<Calibration> CalibrationData { get; set; }
        = new ObservableCollection<Calibration>
        {
            new Calibration {Caption="aaa", Value=1.23 },
            new Calibration {Caption="aaabbb", Value=1.234567 },
            new Calibration {Caption="cc", Value=1.2345 },
            new Calibration {Caption="dddddddd", Value=1.23 },
            new Calibration {Caption="e", Value=1.2345 },
            new Calibration {Caption="ffffff", Value=1.2345 },
            new Calibration {Caption="gggggggggg", Value=1.2345 },
            new Calibration {Caption="aaa", Value=1.2345 },
            new Calibration {Caption="aaa", Value=1.2345 },
            new Calibration {Caption="aaa", Value=1.2345 },
            new Calibration {Caption="aaa", Value=1.2345 },
            new Calibration {Caption="aaa", Value=1.2345 },
            new Calibration {Caption="aaa", Value=1.2345 },
            new Calibration {Caption="aaa", Value=1.2345 },
            new Calibration {Caption="aaa", Value=1.2345 },
            new Calibration {Caption="aaa", Value=1.2345 },
            new Calibration {Caption="aaa", Value=1.2345 }
        };

视图:

   <Window.DataContext>
        <local:MainWindowViewModel/>
    </Window.DataContext>
    <Grid Name="LayoutRoot">
     <ComboBox Height="30"
               ItemsSource="{Binding CalibrationData}"
               MaxDropDownHeight="{Binding MaxDropDownHeight}"/>
    </Grid>
</Window>


这篇关于什么会导致WPF ComboBox的MaxDropDownHeight根据绑定数据被忽略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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