在自定义控件组合框中预选一个条目? [英] Preselect an entry in a custom control combobox?

查看:65
本文介绍了在自定义控件组合框中预选一个条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义控件组合框,用于显示查询结果.为了能够显示结果,我必须像下面这样使用SetBinding:

I have a custom control combobox that displays the result of a query. To be able to display the result I have to use SetBinding like so:

);
comboControl.SetBinding(System.Windows.Controls. ComboBox .ItemsSourceProperty, ,System.Windows.Data. BindingMode comboControl.SetBinding(System.Windows.Controls. ComboBox .SelectedItemProperty, ,System.Windows.Data. BindingMode

IContentItemProxycomboControl = this.FindControl("EntryMaskComboBox");
comboControl.SetBinding(System.Windows.Controls.ComboBox.ItemsSourceProperty, "Screen.DataEntryMasks", System.Windows.Data.BindingMode.TwoWay);
comboControl.SetBinding(System.Windows.Controls.ComboBox.SelectedItemProperty, "Screen.DataEntryMask", System.Windows.Data.BindingMode.TwoWay);

这很好.但是,如何像存在一个SelectedIndex属性那样预选一个项目呢?现在,组合框没有显示条目吗?

关于

彼得



推荐答案

您需要将代理对象转换为自定义组合框类型,然后应该有权使用它 SelectedItem 属性.

You'd need to cast the proxy object to your custom combobox type, then you should have access to its SelectedItem property.

如果这样不能直接访问 SelectedItem 属性,则可能需要添加一个 您的自定义控件(在其代码中)的"依赖项属性",底层的组合框控件.

If that doesn't give you direct access to the SelectedItem property, you may have to add a dependency property to your custom control (in its code), that "talks to" the underlying combobox control.


这篇关于在自定义控件组合框中预选一个条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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