title: C#: How to populate combo items in UserControl
body: <p>The following code works by having the combobox populated by the C# code behind at run-time.
  I would like to populate the user control combos declaratively from XAML, similar to how the description label is populated.
  This code is just for my personal use, so I won't be using complex MVVM models.  I'd ideally like a solution that passes string arrays from the main XAMLcode, to the user control as I'd like to know how to do that.
  Thanks in advance :-)</p>
  <pre><code>        //Main Window.xaml
      &lt;Window
      x:Class=&quot;WpfApp1.MainWindow&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
      xmlns:local=&quot;clr-namespace:WpfApp1&quot;
      mc:Ignorable=&quot;d&quot;
      Title=&quot;Car Details&quot;
      SizeToContent=&quot;WidthAndHeight&quot;&gt;
      
      &lt;StackPanel&gt;
          &lt;local:myControl
              x:Name=&quot;myMake&quot;
              myDescription=&quot;Make&quot; /&gt;
  
          &lt;local:myControl
              x:Name=&quot;myModel&quot;
              myDescription=&quot;Model&quot; /&gt;
  
          &lt;local:myControl
              x:Name=&quot;myYear&quot;
              myDescription=&quot;Year&quot; /&gt;
  
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  
  
      //MainWindow.xaml.cs
  
  using System.Windows;
  namespace WpfApp1
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
  
              //myMake is the name of a specific myControl
              //myOption is the name of the combo within myControl
              myMake.myOptions.ItemsSource = new string[] { &quot;Ford&quot;, &quot;Toyota&quot; };
          }
      }
  }
  
  
      //myControl.xaml
  
  &lt;UserControl
      x:Class=&quot;WpfApp1.myControl&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
      xmlns:local=&quot;clr-namespace:WpfApp1&quot;
      mc:Ignorable=&quot;d&quot;&gt;
      &lt;StackPanel&gt;
          &lt;Label
              Content=&quot;{Binding myDescription,FallbackValue=description}&quot;
              /&gt;
              
          &lt;ComboBox
              x:Name=&quot;myOptions&quot;
              Width=&quot;120&quot; /&gt;
      &lt;/StackPanel&gt;
  &lt;/UserControl&gt;
  
  
  
      //myControl.xaml.cs
  
  using System.Windows;
  using System.Windows.Controls;
  
  namespace WpfApp1
  {
      public partial class myControl : UserControl
      {
          public myControl()
          {
              InitializeComponent();
              this.DataContext = this;
          }
  
          public string myDescription
          {
              get { return (string)GetValue(myDescriptionProperty); }
              set { SetValue(myDescriptionProperty, value); }
          }
  
  public static readonly DependencyProperty myDescriptionProperty = DependencyProperty.Register(&quot;myDescription&quot;, typeof(string), typeof(myControl), new PropertyMetadata(null));
      }
  }
  </code></pre>