Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
private ObservableCollection<FASCNS.ViewModel.Community> _objCommunity;
       public ObservableCollection<FASCNS.ViewModel.Community> objCommunity
       {
           get
           {
               return _objCommunity;
           }
           set
           {
               _objCommunity.Add(new FASCNS.ViewModel.Community { Code = 403, Desc = "Supplier" });
               _objCommunity.Add(new FASCNS.ViewModel.Community { Code = 404, Desc = "Sub Contractor" });
               _objCommunity.Add(new FASCNS.ViewModel.Community { Desc = "Both" });
               _objCommunity.Add(new FASCNS.ViewModel.Community { Desc = "General" });
               _objCommunity = value;
               OnPropertyChanged("objCommunity");

           }
       }



How do add these value to combobox on load in silverlight(MVVM)?
Help. I'm new to silverlight.
Posted

1 solution

There are few changes which you need to do in your code
1-If you want to put predefined values to your in the combobox so it will never hit the set property.
2-You need to set the predefined values as below format
XML
private ObservableCollection<FASCNS.ViewModel.Community> _objCommunity= new ObservableCollection<FASCNS.ViewModel.Community>
        {
        new FASCNS.ViewModel.Community{ Code = 403, Desc = "Supplier" },
        new FASCNS.ViewModel.Community{ Code = 404, Desc = "Sub Contractor" },
        new FASCNS.ViewModel.Community{ Desc = "Both" },
        new FASCNS.ViewModel.Community{ Desc = "General" },
        };


above code will be part of your ViewModel
3-Change in the Xaml

SQL
ItemsSource="{Binding Path=objCommunity}"
DisplayMemberPath="Desc"
SelectedValuePath="Desc"


Hope this will help you in getting values in your combobox , if you want first value will be selected by default make selectedIndex=0

Regards,
Vinod
 
Share this answer
 
Comments
Sathish km 24-Sep-15 9:20am    
Thank a lot! But DisplayMemberPath & SelectedValuePath property cannot be declared.
how?

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