1
votes

I have a simple custom tree view component:

  public partial class ThemesTreeView: UserControl, IThemesTreeView {
  public delegate void ThemeSelected(ThemeModel theme);
  public event ThemeSelected OnThemeSelection;

  public delegate void ThemeDoubleClick(ThemeModel theme);
  public event ThemeDoubleClick OnThemeDoubleClick;

  public ThemesTreeView() {
   InitializeComponent();
  }   


  private void UserControl_Loaded(object sender, RoutedEventArgs e) {      
   var caseCovers = GetTreeViewItem((Int32) ThemeType.CaseCover, "1", "Case Covers", "album_cover.png");
   var musics = GetTreeViewItem((Int32) ThemeType.Music, "1", "Music", "music_run.png");
   var movies = GetTreeViewItem((Int32) ThemeType.Video, "1", "Scenic Video Inserts", "video.png");   

   tvThemes.Items.Add(caseCovers);
   tvThemes.Items.Add(musics);
   tvThemes.Items.Add(movies);
  }

  private ThemesTreeViewItem GetTreeViewItem(Int32 tag, String uid, String text, String imagePath) {
   ThemesTreeViewItem item = new ThemesTreeViewItem();
   item.Uid = uid;
   item.Tag = tag;
   item.IsExpanded = false;

   // create stack panel
   StackPanel stack = new StackPanel();
   stack.Orientation = Orientation.Horizontal;

   // create Image
   Image image = new Image();
   image.Source = new BitmapImage(new Uri("pack://application:,,/images/" + imagePath));
   image.Width = 16;
   image.Height = 16;
   // Label
   Label lbl = new Label();
   lbl.Content = text;

   // Add into stack
   stack.Children.Add(image);
   stack.Children.Add(lbl);

   // assign stack to header
   item.Header = stack;
   return item;
  }
 }
}

I have skipped some code for downloading and filling subnodes. When user clicks on a node then subnodes are downloaded and addded to treeview. But the problem is there is no arrow for expand/collapse until nodes will be added. How to show arrow always?

1

1 Answers

1
votes

Make a copy of the treeviewitem Style. Find Part of the treenode and correct the Style of the Node similar to the state of treenode with subnodes.

here description of styling for treeviewite-controltemplate