Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
C#
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));
        }
    }
}
Posted
Updated 4-Mar-13 21:02pm
v2

1 solution

Basically, you have to use "ItemSource", "SelectedValuePath", "DisplayMemberPath" property with respective binding.
XML
<combobox itemssource="{Binding Path=AvailableTypes}">
          SelectedValuePath="[your selected value path]"
          DisplayMemberPath="[your display member path]" />
</combobox>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900