我有一个简单的自定义树视图组件:
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;
}
}
}
我已经跳过一些下载和填充子节点的代码。当用户单击某个节点时,将下载子节点并将其添加到树视图中。但问题是在添加节点之前没有用于展开/折叠的箭头。如何永远显示箭头?
答案 0 :(得分:1)
制作treeviewitem Style的副本。找到treenode的一部分并更正节点的样式,类似于带有子节点的treenode的状态。