title: WPF: Binding UserControl inside ItemsControl
body: <p>I'm tryin to make some wpf, which displays my user control for every day of some date range. So far ive tryied datagrid, but it does not support different data type of rows, so I'm tryin to solve it by UserControl and ItemsControl.
  <br>
  My UserControl - PeriodDayControl.xaml looks like this:</p>
  <pre><code>&lt;UserControl x:Class=&quot;WpfApp.PeriodDayControl&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:WpfApp&quot;
               mc:Ignorable=&quot;d&quot; Height=&quot;168.443&quot; Width=&quot;104.098&quot;&gt;
      &lt;Grid&gt;
          &lt;TextBox Text=&quot;{Binding Path=name}&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;23&quot; Margin=&quot;20,10,21,0&quot; TextWrapping=&quot;Wrap&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;63&quot; TextAlignment=&quot;Center&quot;/&gt;
          &lt;TextBox Text=&quot;{Binding Path=price}&quot; HorizontalAlignment=&quot;Left&quot; Height=&quot;23&quot; Margin=&quot;31,61,0,0&quot; TextWrapping=&quot;Wrap&quot;  VerticalAlignment=&quot;Top&quot; Width=&quot;41&quot; TextAlignment=&quot;Center&quot;/&gt;
          &lt;CheckBox IsChecked=&quot;{Binding Path=check}&quot;  Content=&quot;CheckBox&quot; HorizontalAlignment=&quot;Left&quot; VerticalAlignment=&quot;Top&quot; Margin=&quot;42,117,0,0&quot; Height=&quot;16&quot; Width=&quot;16&quot; RenderTransformOrigin=&quot;0.372,0.449&quot;/&gt;
  
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  <p>And code to register properties for binding (PeriodDayControl.xaml.cs):</p>
  <pre><code>        public PeriodDayControl()
          {
              InitializeComponent();
          }
  
          public string name
          {
              get { return (string)GetValue(nameProperty); }
              set { SetValue(nameProperty, value); }
          }
  
          public static readonly DependencyProperty nameProperty =
              DependencyProperty.Register(&quot;name&quot;, typeof(string), typeof(PeriodDayControl));
  
          public decimal price
          {
              get { return (decimal)GetValue(priceProperty); }
              set { SetValue(priceProperty, value); }
          }
  
          public static readonly DependencyProperty priceProperty =
              DependencyProperty.Register(&quot;price&quot;, typeof(decimal), typeof(PeriodDayControl));
  
          public bool check
          {
              get { return (bool)GetValue(checkProperty); }
              set { SetValue(checkProperty, value); }
          }
  
          public static readonly DependencyProperty checkProperty =
              DependencyProperty.Register(&quot;check&quot;, typeof(bool), typeof(PeriodDayControl));
  
  </code></pre>
  <p>So it look's like this in designer:<br>
  <a href="https://i.stack.imgur.com/l3Oan.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l3Oan.png" alt="enter image description here" /></a></p>
  <p>In MainWindow.xaml I'm trying to use Items control, to create template:<br></p>
  <pre><code>        &lt;ItemsControl x:Name=&quot;ItemsControlMain&quot; ItemsSource=&quot;{Binding ViewModels}&quot; Margin=&quot;0,166,0,0&quot;&gt;
              &lt;ItemsControl.ItemsPanel&gt;
                  &lt;ItemsPanelTemplate&gt;
                      &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;&lt;/StackPanel&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/ItemsControl.ItemsPanel&gt;
              &lt;ItemsControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;local:PeriodDayControl name=&quot;{Binding Path=nameProperty}&quot; price=&quot;{Binding Path=priceProperty}&quot; check=&quot;{Binding Path=checkProperty}&quot;/&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ItemsControl.ItemTemplate&gt;
          &lt;/ItemsControl&gt;
  </code></pre>
  <p>and here is my try to create and populate data to PeriodDayControl:</p>
  <pre><code>            List&lt;PeriodDayControl&gt; pdcList = new List&lt;PeriodDayControl&gt;();
              pdcList.Add(new PeriodDayControl() { name = &quot;01/01&quot;,price =(decimal)55, check=true});
              pdcList.Add(new PeriodDayControl() { name = &quot;02/01&quot;,price =(decimal)55, check=false});
              pdcList.Add(new PeriodDayControl() { name = &quot;03/01&quot;,price =(decimal)55, check=true});
              ObservableCollection&lt;PeriodDayControl&gt; pdcColl = new ObservableCollection&lt;PeriodDayControl&gt;(pdcList);
              ItemsControlMain.ItemsSource = pdcColl;
  </code></pre>
  <p>Here is how it looks now:<br>
  <a href="https://i.stack.imgur.com/fdtxT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fdtxT.png" alt="enter image description here" /></a></p>
  <p>And finally here is what I'm trying to achive:<br>
  <a href="https://i.stack.imgur.com/hS0PP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hS0PP.png" alt="enter image description here" /></a></p>
  <p>Right now it shows:<br>
  <a href="https://i.stack.imgur.com/c09ii.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c09ii.png" alt="enter image description here" /></a></p>
  <p>And here are my questions. Is it right decision to use ItemsControl? Or are there any other posibilities, to achive such funcionality? What's wrong with this solution(why it does not populate data)? To make context, I would like to change checkbox/price and then press button , which will read data from all of UserControl and save it to db.<br><strong>Thank you for any advice.</strong></p>