1

I have a multi-level WPF TreeView that uses HierachicalDataTemplate to bind to my view model. I want to see how the tree will look fully expanded at design time, but since the designer doesn't allow you to click on the nodes, I have been trying to find a design-time only solution using mc:Ignorable="d" and ItemContainerStyle.

I have kind of been able to do this as shown below. By itself the TreeView.ItemContainerStyle section does exactly as I would like it to, but when I add a d:, suddenly the designer acts like the style isn't there and collapses all the tree nodes. The designer doesn't show any errors or warnings.

 <TreeView ItemsSource="{Binding ParentCollection}">
     <d:TreeView.ItemContainerStyle>
         <Style TargetType="{x:Type TreeViewItem}">
             <Setter Property="IsExpanded" Value="True"/>
         </Style>
     </d:TreeView.ItemContainerStyle>
     <TreeView.ItemTemplate>
         <HierarchicalDataTemplate ItemsSource="{Binding ChildItems}">
             <!-- And so on -->
         </HierarchicalDataTemplate>
     </TreeView.ItemTemplate>
 </TreeView>

Is there a good way for me to view my tree nodes expanded at design time, but have them start as collapsed at runtime?

spectacularbob
  • 3,080
  • 2
  • 20
  • 41
  • Personally I just [do this](http://stackoverflow.com/questions/32872212/create-properties-that-only-apply-on-design-time) though I'm unsure if I'd mark it a duplicate in this instance. – Chris W. Apr 13 '17 at 16:55
  • That does work, but I'm not sure I like that it doesn't compile it out like the d: tag does – spectacularbob Apr 13 '17 at 17:34

0 Answers0