title: C# WPF MVVM set selected in xaml with calendar type app
body: <p>I'm relatively new to WPF and MVVM, I have only written one other MVVM application. I would like to create my own calendar app but I'm having trouble setting the selected day.</p>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>&lt;Grid Background="White"&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="Auto"/&gt;
          &lt;RowDefinition/&gt;
      &lt;/Grid.RowDefinitions&gt;
  
      &lt;Grid Grid.Row="0"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="1*"/&gt;
              &lt;ColumnDefinition Width="8*"/&gt;
              &lt;ColumnDefinition Width="1*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="3" &gt;
              &lt;TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="&amp;lt;"&gt;&lt;/TextBlock&gt;
          &lt;/Button&gt;
          &lt;Label HorizontalAlignment="Center" VerticalAlignment="Top" x:Name="CalendarTitle" Content="{Binding Path=DateTitle}" Grid.Column="1"/&gt;
          &lt;Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="3" Grid.Column="2" Content="&amp;gt;"/&gt;
      &lt;/Grid&gt;
  
      &lt;Grid Grid.Row="1"&gt;
          &lt;ItemsControl ItemsSource="{Binding Days}"&gt;
              &lt;ItemsControl.ItemsPanel&gt;
                  &lt;ItemsPanelTemplate&gt;
                      &lt;UniformGrid Rows="5" Columns="7" FirstColumn="3"/&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/ItemsControl.ItemsPanel&gt;
              &lt;ItemsControl.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Border BorderBrush="Black" BorderThickness="1"&gt;
                          &lt;Grid Background="Transparent" MouseDown="Grid_MouseDown" MouseLeave="Grid_MouseLeave" MouseEnter="Grid_MouseEnter"&gt;
                              &lt;Grid.RowDefinitions&gt;
                                  &lt;RowDefinition/&gt;
                                  &lt;RowDefinition/&gt;
                              &lt;/Grid.RowDefinitions&gt;
                              &lt;Label Content="{Binding DayNumber}"&gt;&lt;/Label&gt;
                              &lt;Label Content="{Binding Message}" VerticalAlignment="Center" HorizontalAlignment="Center"&gt;&lt;/Label&gt;
                          &lt;/Grid&gt;
                      &lt;/Border&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ItemsControl.ItemTemplate&gt;
          &lt;/ItemsControl&gt;
      &lt;/Grid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>Using ItemsControl and Binding its ItemsSource to an ObservableCollection will work with bringing up data fine, how do I also properly create a SelectedDay attribute?</p>
  
  <p><strong>ViewModel</strong></p>
  
  <pre><code>public class CalendarCellsViewModel : BaseINPC
  {
      public CalendarCellsViewModel()
      {
          DateTitle = $"{CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(DateTime.Today.Month)} {DateTime.Today.Year}";
  
          for(int i = 1; i &lt;= 31; i++)
          {
              Days.Add(new CalendarDayData { DayNumber = i, Message = "Test" });
          }
      }
  
      private string _dateTitle;
      public string DateTitle
      {
          get { return _dateTitle; }
          set { SetProperty(ref _dateTitle, value); }
      }
  
      private ObservableCollection&lt;CalendarDayData&gt; _days = new ObservableCollection&lt;CalendarDayData&gt;();
  
      public ObservableCollection&lt;CalendarDayData&gt; Days
      {
          get { return _days; }
          set { SetProperty(ref _days, value); }
      }
  }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class CalendarDayData : BaseINPC
  {
      public CalendarDayData()
      {
  
      }
      public int DayNumber { get; set; }
      public int ReminderStart { get; set; }
      public int ReminderFrequency { get; set; }
      public string Message { get; set; }
  
      private bool _selectedDay = false;
      public bool SelectedDay
      {
          get { return _selectedDay; }
          set
          {
              if (_selectedDay != value)
              {
                  _selectedDay = value;
                  SetProperty(ref _selectedDay, value);
              }
          }
      }
  }
  </code></pre>
  
  <p>Any tips or good resources I should take a look at?</p>