Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I have some difficulties binding data into combobox in xaml. I made very simple example to work with.

Ok, here it goes.

I have following enum:
public enum ShirtSize
        {
            Small,
            Medium,
            Large
        }

And I know that I can fill my combobox "comboBoxShirtSizes" incode like follows:
foreach (ShirtSize e in Enum.GetValues(typeof(ShirtSize)))
      comboBoxShirtSizes.Items.Add(e);

  //Or

  comboBoxShirtSizes.ItemsSource = Enum.GetValues(typeof(ShirtSize));

The Question is how to do same just using Xaml code :doh: ?

bests regards
Posted
Updated 13-Dec-10 2:17am
v3

Hi,

Look into bindings using XAML. You are able to set the data source of certain controls which, once bound to collections in your code behind will display that content. If you use dependency properties you're able to update these collections which in tern updates your graphical display.

I hope this helps.

Laurence
 
Share this answer
 
Comments
paleGegg0 14-Dec-10 1:45am    
I have managed to bind dependency properties with textboxes in xaml, but filling combobox with enums seems to be trivial to me. I have tried ObjectdataProvider and many different other ways to do it in xaml without success. It can be typo or something in my code but my combobox remains empty. Thats why I made that example code above that someone could make example binding in xaml.
It was typo afterall. Using ObjectdataProvider in xaml solved my problem. Also needed add my class in reference in xaml... :)
 
Share this answer
 
Comments
Laurence1234 15-Dec-10 5:17am    
Cool. Remembering the reference in the XAML file is sometimes a tricky one. I often get the namespaces mixed up in a larger project.

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