Trivial data binding in WPF

I am trying to populate a combobox using an ObservableList or a List object that I get from a method call (GetYears).

The ObjectDataProvider looked promising, but when I try to use it, I get "x: the key is only allowed for resources and dictionary items" and has difficulty in where I have to put it in my xaml.

I am currently doing the same thing using the following snippet, but I find it against the best practices of WPF and more of WinForms.

public partial class MainWindow : Window
{
  public MainWindow()
  {
    YearComboBox.ItemsSource = GetYears();
}...

I view the following pages

http://msdn.microsoft.com/en-us/library/aa480224.aspx and this page http://www.codeproject.com/Articles/140621/WPF-Tutorial-Concept-Binding and reading speed of the next book "Pro WPF in C # 2010 "

Android/c/++ - .Net/WPF WPF. MVVM, , ; , . MVVM.sln? , UML- MVVM? , , .

+4
2

ObjectDataProvider .

, place it under Resource section of root ( , UserControl, ..)

, ( ):

<StackPanel Orientation="Vertical" xmlns:m="clr-namespace:ActualNamespace">

    <StackPanel.Resources>
      <ObjectDataProvider ObjectType="{x:Type m:StringData}"
         x:Key="objStrings" MethodName="GetStrings"/>
    </StackPanel.Resources>

    <ComboBox Name="lstStrings" Width="200" Height="300"
           ItemsSource="{Binding Source={StaticResource objStrings}}" />

</StackPanel>
+4

All Articles