tags:

views:

29

answers:

1

If I have a property in my C#;

    public CollectionView Months
    {
        get 
        {
            CollectionView retList = new Enumerations.Months().ToCollectionView<Enumerations.Months>();
            return retList;
        }
    }

And I have a ComboBox;

<ComboBox x:Name="ddlMonth" Grid.Row="3" Grid.Column="1" 
ItemsSource="{Binding Source={StaticResource Months}}"/>

How can I bind my ComboBox to my property?

I should add I'm a complete xaml newbie.

+1  A: 

First up, that isn't a method - it is a property.

All you have to do is this:

<ComboBox x:Name="ddlMonth" Grid.Row="3" Grid.Column="1" ItemsSource="{Binding Months}"/>

The trick is to ensure that whatever class the property Months appears in is set as the DataContext of the ComboBox or one of its parents (including the Page).

So if the Months property appears in the same page that hosts the ComboBox, then you can add this line of code in the constructor or Loaded event of the page:

this.DataContext = this;

If the Months property appears in a ViewModel (which i hope it does!) then you need to assign the ViewModel to the DataContext of the page (or a subsidiary control that is still a parent (ancestor) of the ComboBox).

slugster
+1, Oops, yeah sorry not method, Property. Editied question. thanks.
griegs