silverlight 怎么取treeview里面treeview checkbox选中的值
展开全部
如果只存在一级 可以直接用
TreeView t=new TreeView();
CheckBox chk=new CheckBox();
t.Items.add(chk);
如果多级可用
TreeView t=new TreeView();
TreeViewItem tvi=new TreeViewItem();
t.Items.add(tvi);
CheckBox chk=new CheckBox();
tvi.Items.add(chk);
1.获取值的方法很多 可以在CheckBox 加入Click事件 在事件中保存值
2.可以遍历TreeView
这种比较容易理解
Q 461577587
//方法二 同上面这位回答的 绑定获取
TreeView t=new TreeView();
CheckBox chk=new CheckBox();
t.Items.add(chk);
如果多级可用
TreeView t=new TreeView();
TreeViewItem tvi=new TreeViewItem();
t.Items.add(tvi);
CheckBox chk=new CheckBox();
tvi.Items.add(chk);
1.获取值的方法很多 可以在CheckBox 加入Click事件 在事件中保存值
2.可以遍历TreeView
这种比较容易理解
Q 461577587
//方法二 同上面这位回答的 绑定获取
追问
最近又发现个问题了, 我发现我不打开树前面的三角形 他就不会遍历这项的子项! WHY
遍历代码foreach(TreeViewItem tree in treeView1.GetDescendantContainers())
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在View中注册属性 像这样
<telerik:ContainerBindingCollection x:Name="BindingsCollection">
<telerik:ContainerBinding PropertyName="CheckState" Binding="{Binding IsChecked, Mode=TwoWay}" />
<telerik:ContainerBinding PropertyName="IsSelected" Binding="{Binding IsSelected, Mode=TwoWay}" />
<telerik:ContainerBinding PropertyName="IsExpanded" Binding="{Binding IsExpanded, Mode=TwoWay}" />
</telerik:ContainerBindingCollection>
<telerik:RadTreeView Background="White"
ItemsOptionListType="CheckList"
IsOptionElementsEnabled="True"
IsLineEnabled="True"
SelectionMode="Extended"
IsTriStateMode="True"
IsRootLinesEnabled="True"
ItemTemplate="{StaticResource CategoryTemplate}"
ItemsSource="{Binding Path=TypeSource,Mode=TwoWay}"
telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}">
</telerik:RadTreeView>
然后在 后台cs或是ViewModel中 定义一个类、属性 像这样
public class HPTypeEx : INotifyPropertyChanged
{
public HPTypeEx()
{
this.IsChecked = ToggleState.Off;
this.IsSelected = false;
this.isExpanded = false;
}
public string TypeName { get; set; }
public int HTypeValue{ get; set; }
public ETenderEnumBindingBase InnerHType { get; set; }
public List<PTypeEx> InnerTypes { get; set; }
private ToggleState isChecked;
private bool isSelected, isExpanded;
public bool IsExpanded
{
get
{
return this.isExpanded;
}
set
{
if (this.isExpanded != value)
{
this.isExpanded = value;
OnNotifyPropertyChanged("IsExpanded");
}
}
}
public ToggleState IsChecked
{
get
{
return this.isChecked;
}
set
{
if (this.isChecked != value)
{
this.isChecked = value;
OnNotifyPropertyChanged("IsChecked");
}
}
}
public bool IsSelected
{
get
{
return this.isSelected;
}
set
{
if (this.isSelected != value)
{
this.isSelected = value;
OnNotifyPropertyChanged("IsSelected");
}
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnNotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
如还有不解 加QQ:406061153
<telerik:ContainerBindingCollection x:Name="BindingsCollection">
<telerik:ContainerBinding PropertyName="CheckState" Binding="{Binding IsChecked, Mode=TwoWay}" />
<telerik:ContainerBinding PropertyName="IsSelected" Binding="{Binding IsSelected, Mode=TwoWay}" />
<telerik:ContainerBinding PropertyName="IsExpanded" Binding="{Binding IsExpanded, Mode=TwoWay}" />
</telerik:ContainerBindingCollection>
<telerik:RadTreeView Background="White"
ItemsOptionListType="CheckList"
IsOptionElementsEnabled="True"
IsLineEnabled="True"
SelectionMode="Extended"
IsTriStateMode="True"
IsRootLinesEnabled="True"
ItemTemplate="{StaticResource CategoryTemplate}"
ItemsSource="{Binding Path=TypeSource,Mode=TwoWay}"
telerik:ContainerBinding.ContainerBindings="{StaticResource BindingsCollection}">
</telerik:RadTreeView>
然后在 后台cs或是ViewModel中 定义一个类、属性 像这样
public class HPTypeEx : INotifyPropertyChanged
{
public HPTypeEx()
{
this.IsChecked = ToggleState.Off;
this.IsSelected = false;
this.isExpanded = false;
}
public string TypeName { get; set; }
public int HTypeValue{ get; set; }
public ETenderEnumBindingBase InnerHType { get; set; }
public List<PTypeEx> InnerTypes { get; set; }
private ToggleState isChecked;
private bool isSelected, isExpanded;
public bool IsExpanded
{
get
{
return this.isExpanded;
}
set
{
if (this.isExpanded != value)
{
this.isExpanded = value;
OnNotifyPropertyChanged("IsExpanded");
}
}
}
public ToggleState IsChecked
{
get
{
return this.isChecked;
}
set
{
if (this.isChecked != value)
{
this.isChecked = value;
OnNotifyPropertyChanged("IsChecked");
}
}
}
public bool IsSelected
{
get
{
return this.isSelected;
}
set
{
if (this.isSelected != value)
{
this.isSelected = value;
OnNotifyPropertyChanged("IsSelected");
}
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void OnNotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
如还有不解 加QQ:406061153
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询