wpftreeview多选(wpf listview多选)
wpf treeview中动态创建的treeViewItem如何用右键触发菜单?
public class ResourcesSettingViewModel : SoftGuidanceViewModelBase
2 {
3 #region Contructor
4 public ResourcesSettingViewModel()
5 : this(new ResourcesSettingModel())
6 {
7
8 }
9 public ResourcesSettingViewModel(ResourcesSettingModel resourcesSettingModel)
10 {
11 this.resourcesSettingModel = resourcesSettingModel;
12
13 }
14 #endregion
15 #region Variables
16
17 private ResourcesSettingModel resourcesSettingModel;
18
19 #endregion
20 #region Properties
21 public ResourcesSettingModel ResourcesSettingModel
22 {
23 get { return this.resourcesSettingModel; }
24 }
25 private EverTreeViewItem selectedTreeViewItem;
26
27
28 public EverTreeViewItem SelectedTreeViewItem
29 {
30 get { return this.selectedTreeViewItem; }
31 set
32 {
33 if (this.selectedTreeViewItem == value)
34 {
35 return;
36 }
37 this.selectedTreeViewItem = value;
38 this.RaisePropertyChanged(() = this.SelectedTreeViewItem);
39 }
40 }
41
42
43 #endregion
44 #region Command
45 public ICommand MenuAddCommand
46 {
47 get
48 {
49 return new DelegateCommand(()=
50
51 {
52 MessageBox.Show("");
53 });
54 }
55 }
56
57
58
59
60
61 #endregion
62
63 //private EverTreeViewItem GetSelectdTreeViewItem()
64 //{
65 // EverTreeViewItem treeViewItem = (EverTreeViewItem)SelectedTreeViewItem;
66 // return treeViewItem;
67 //}
68 }
WPF中Treeview中的节点可以做到下图的样子吗
WPF中TreeView的items一般为TreeViewItem,同时TreeViewItem自身又可以包含新的TreeViewItem,从而形成一棵子树,你想要几级节点就有几级节点了。
C#如下:
TreeView treeView = new TreeView();
//第一级,在treeView上添加
TreeViewItem treeViewItem1 = new TreeViewItem();
treeViewItem1.Header = "第一级";
treeView.Items.Add(treeViewItem1);
//第二级,在treeViewItem1上添加
TreeViewItem treeViewItem2 = new TreeViewItem();
treeViewItem2.Header = "第二级";
treeViewItem1.Items.Add(treeViewItem2);
//第三级,在treeViewItem2上添加
TreeViewItem treeViewItem3 = new TreeViewItem();
treeViewItem3.Header = "第三级";
treeViewItem2.Items.Add(treeViewItem3);
WPF的listbox有selecteditem属性可以用来做绑定那TreeView里有类似的属性可以用来绑定来获取选中的的值吗
可以定义类似如下的style
????Grid
????????Grid.Resources
????????????Style?x:Key="SelectStyle"?TargetType="TreeViewItem"
????????????????Setter?Property="IsSelected"?Value="{Binding?你的属性}"
????????????????/Setter
????????????/Style
????????/Grid.Resources
????????TreeView
????????/TreeView
????/Grid
对于wpf中的treeview控件,不了解其用法,能否给出一个:
随便写了一段,测试通过了 public Window1()
{
InitializeComponent();
ContextMenu menu = new ContextMenu();
MenuItem itemAdd = new MenuItem(); itemAdd.Header = "添加节点";
MenuItem itemDel = new MenuItem();
itemDel.Header = "删除节点";
menu.Items.Add(itemAdd);
menu.Items.Add(itemDel);
TreeView treeView = new TreeView();
TreeViewItem root = new TreeViewItem();
root.Header = "根节点";
root.ContextMenu = menu; treeView.Items.Add(root);
this.Content = treeView;
itemAdd.Click += delegate
{
if (treeView.SelectedItem != null)
{
TreeViewItem leave = new TreeViewItem();
leave.Header = "新节点";
TreeViewItem parent = treeView.SelectedItem as TreeViewItem;
parent.Items.Add(leave);
leave.ContextMenu = menu;
}
};
itemDel.Click += delegate
{
if (treeView.SelectedItem != null)
{
TreeViewItem leave = treeView.SelectedItem as TreeViewItem;
if (leave.Parent != null)
{
TreeViewItem parent = leave.Parent as TreeViewItem;
parent.Items.Remove(leave);
}
else
{
treeView.Items.Remove(leave);
}
}
};
}
WPF程序里,有一个ListView,想要在其中拖动鼠标,生成一个矩形框,并选中矩形框中的item元素,该怎么做
定义一个样式就行了~很简单。样式里面有状态和触发器,你可以为treeviewitem定义样式,设置状态过度。