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.
First up, that isn’t a method – it is a property.
All you have to do is this:
The trick is to ensure that whatever class the property
Monthsappears in is set as theDataContextof the ComboBox or one of its parents (including the Page).So if the
Monthsproperty appears in the same page that hosts the ComboBox, then you can add this line of code in the constructor orLoadedevent of the page:If the
Monthsproperty appears in a ViewModel (which i hope it does!) then you need to assign the ViewModel to theDataContextof the page (or a subsidiary control that is still a parent (ancestor) of the ComboBox).