Bind Treeview In WPF
TreeView Xmal
<TreeView x:Name="TvWorkItem" Grid.Column="0" Grid.Row="2" Background="Black" ItemsSource="{Binding MenuDataSource}" SelectedItemChanged="TreeView_OnSelectedItemChanged"> <TreeView.ItemTemplate > <span style="color:#ff0000;"> <HierarchicalDataTemplate ItemsSource="{Binding ChildItems}"> <TextBlock Text="{Binding Name}" Background="Black" > </span> <TextBlock.Style > <Style TargetType="TextBlock"> <Style.Triggers> <DataTrigger Binding="{Binding HasOutStandingTask}" Value="true"> <Setter Property="Foreground" Value="DarkOrange" /> <Setter Property="FontSize" Value="16"></Setter> </DataTrigger> <DataTrigger Binding="{Binding HasOutStandingTask}" Value="false"> <Setter Property="Foreground" Value="Aqua" /> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock> </HierarchicalDataTemplate> </TreeView.ItemTemplate> </TreeView>
更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/
ViewModel
private ObservableCollection<MenuItem> _menuDataSource; public ObservableCollection<MenuItem> MenuDataSource { get { if (_menuDataSource == null) _menuDataSource = MenuOperation.LoadMenu(); return _menuDataSource; } set { _menuDataSource = value; RaisePropertyChanged(() => MenuDataSource); } }
Entity
public class MenuItem { public Guid Id { get; set; } public string Name { get; set; } public string OriName { get; set; } public bool HasOutStandingTask { get; set; } public <span style="color:#ff0000;">ObservableCollection<MenuItem></span> ChildItems { get; set; } public bool IsWorkItemType { get; set; } public WorkItemType WorkType { get; set; } public bool IsWorkItem { get; set; } }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索treeview
, string
, set
, get
, bool
public
wpf binding、wpf multibinding、wpf binding path、wpf templatebinding、wpf command binding,以便于您获取更多的相关知识。
时间: 2024-12-03 12:00:09