将observerbaleCollection绑定到wpf组合框 [英] Bind observerbaleCollection to wpf combo box

查看:83
本文介绍了将observerbaleCollection绑定到wpf组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用类调用Apps.It有Observable集合,名为AvailableTypes.I想要将此AvailableTypes可观察集合绑定到wpf组合框。当表单加载时,这些AppId应该加载到组合框中..你能不能给我解决这个问题?

  class 应用程序:INotifyPropertyChanged {

ServiceReference1 .AssetManagerServiceClient客户端;
ObservableCollection< string> availableType;

public ObservableCollection< string> AvailableTypes
{
get
{
if ( availableType == null
{
availableType = new ObservableCollection< string>( );

}
client = new ServiceReference1.AssetManagerServiceClient();
List< string> AssestList = client.GetAppIds()。ToList< string>();

foreach string appid in AssestList)
{
availableType.Add(appid);
}

return availableType;
}

set
{
availableType = value ;
NotifyPropertyChanged( AvailableTypes);
}
}

public event PropertyChangedEventHandler PropertyChanged ;

private void NotifyPropertyChanged( string propertyName)
{
if (PropertyChanged!= null
PropertyChanged( this new PropertyChangedEventArgs(propertyName));
}
}
}

解决方案

基本上,你必须使用 ItemSource SelectedValuePath DisplayMemberPath 具有相应绑定的属性。

 <   combobox     itemssource   =  {Binding Path = AvailableTypes} >  
SelectedValuePath =[您选择的值路径]
DisplayMemberPath = [您的展示会员路径]/>
< / combobox >


I''m having Class call Apps.It has Observable collection called AvailableTypes.I want to bind this AvailableTypes observable collection to the wpf Combo Box.when form is loaded these AppId should loaded into combo box.. Would you give me a solution to this one?

class Apps: INotifyPropertyChanged{

        ServiceReference1.AssetManagerServiceClient client;
        ObservableCollection<string> availableType;

        public ObservableCollection<string> AvailableTypes
        {
            get
            {
                if (availableType == null)
                {
                    availableType = new ObservableCollection<string>();

                }
                client = new ServiceReference1.AssetManagerServiceClient();
                List<string> AssestList = client.GetAppIds().ToList<string>();

                foreach (string appid in AssestList)
                {
                    availableType.Add(appid);
                }

                return availableType;
            }

            set
            {
                availableType = value;
                NotifyPropertyChanged("AvailableTypes");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

解决方案

Basically, you have to use "ItemSource", "SelectedValuePath", "DisplayMemberPath" property with respective binding.

<combobox itemssource="{Binding Path=AvailableTypes}">
          SelectedValuePath="[your selected value path]"
          DisplayMemberPath="[your display member path]" />
</combobox>


这篇关于将observerbaleCollection绑定到wpf组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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