title: Expand path in TreeView using view model
body: <p>I have dates bounded to TreeView. There is a wrapper class for date. Dates groups by years and months. Wrapper class also has IsSelected and IsExpanded properties:</p>
  
  <pre><code>public sealed class DateViewModel : NotificationObject, IEditableObject
  {
      #region properties
  
      bool _isSelected;
  
      public bool IsSelected
      {
          get
          {
              return _isSelected;
          }
          set
          {
              if (_isSelected != value)
              {
                  _isSelected = value;
                  RaisePropertyChanged(() =&gt; IsSelected);
              }
          }
      }
  
  
      bool _isExpanded;
  
      public bool IsExpanded
      {
          get
          {
              return _isExpanded;
          }
          set
          {
              if (_isExpanded != value)
              {
                  _isExpanded = value;
                  RaisePropertyChanged(() =&gt; IsExpanded);
              }
          }
      }
  
      DateTime _date;
  
      public DateTime Date
      {
          get
          {
              return _date;
          }
          set
          {
              if (_date != value)
              {
                  _date = value;
  
                  RaisePropertyChanged(() =&gt; Date);
                  RaisePropertyChanged(() =&gt; Year);
                  RaisePropertyChanged(() =&gt; Month);
                  RaisePropertyChanged(() =&gt; MonthName);
                  RaisePropertyChanged(() =&gt; Day);
              }
          }
      }
  
      public int Year
      {
          get
          {
              return Date.Year;
          }
      }
  
      public int Month
      {
          get
          {
              return Date.Month;
          }
      }
  
      public string MonthName
      {
          get
          {
              return CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Date.Month);
          }
      }
  
      public int Day
      {
          get
          {
              return Date.Day;
          }
      }
  
      #endregion properties
  }
  </code></pre>
  
  <p>ObservableCollection of DateViewModel is used as ItemsSource for TreeView. Dates groups by CollectionViewSource ans DataTemplates:</p>
  
  <pre><code>&lt;DataTemplate x:Key="DayTemplate"&gt;
      &lt;TextBlock x:Name="textBlock"
                 FontSize="14"
                 Text="{Binding Path=Day}" /&gt;
  &lt;/DataTemplate&gt;
  
  &lt;HierarchicalDataTemplate x:Key="MonthTemplate"
                            ItemsSource="{Binding Path=Items}"
                            ItemTemplate="{StaticResource DayTemplate}"&gt;
      &lt;TextBlock Text="{Binding Path=Name}" /&gt;
  &lt;/HierarchicalDataTemplate&gt;
  
  &lt;HierarchicalDataTemplate x:Key="YearTemplate"
                            ItemsSource="{Binding Path=Items}"
                            ItemTemplate="{StaticResource MonthTemplate}"&gt;
      &lt;TextBlock&gt;
          &lt;Run Text="{Binding Path=Name, Mode=OneWay}" /&gt;
          &lt;Run Text="y" /&gt;
      &lt;/TextBlock&gt;
  &lt;/HierarchicalDataTemplate&gt;
  
  &lt;telerik:RadTreeView   Grid.Row="1"
            ItemsSource="{Binding Path=Dates.View.Groups}"
            ItemTemplate="{StaticResource YearTemplate}"&gt;           
      &lt;telerik:RadTreeView.ItemContainerStyle&gt;
          &lt;Style TargetType="{x:Type telerik:RadTreeViewItem}"&gt;
              &lt;Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" /&gt;
              &lt;Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" /&gt;
          &lt;/Style&gt;
      &lt;/telerik:RadTreeView.ItemContainerStyle&gt;
  &lt;/telerik:RadTreeView&gt;
  </code></pre>
  
  <p>The issue is: I need to expand full path to date using view model by setting IsExpanded property to true. But it doesn't have effect.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Yes I created group descriptions in code. The code for expanding is simple:</p>
  
  <pre><code>public sealed class DatesViewModel
  {
      ObservableCollection&lt;DateViewModel&gt; _dates = new ObservableCollection&lt;DateViewModel&gt;();
      public CollectionViewSource Dates {get; set;}
  
      public DatesViewModel()
      {
          Dates = new CollectionViewSource { Source = _dates } ;
  
          // add groups, sorts and fill collection
          ...
      }
  
      // Just a sample
      public void ExpandFirstDate()
      {
          _dates[0].IsExpanded = true;
      }
  }
  </code></pre>
  
  <p>There is missing code above.</p>
  
  <p>Also I prepared test sample <a href="https://skydrive.live.com/redir.aspx?cid=09f9aac932650216&amp;resid=9F9AAC932650216!140" rel="nofollow">TreeViewGroupingSample.7z</a></p>