I have a treeview that is binded to a class:
The problem is that I want to add a property that if they have the treeviewitem, to activate or deactivate parts of the tree, but when bindear a class of its own, I do not know how to add that property.
Probe:
- derive my class from treeviewitem (I did not stick the bind, eye maybe I did that wrong)
- add an enable property (go, but I do not know what to do with that property).
- transform tree items to treeviewitem (did not walk, are not of that type).
Then how do I tell the tree that certain items are deactivated (grisandolos, underlining, no matter how, but so that the user can not click on them).
Definition of the tree (xalm)
<TreeView x:Name="treeView2" >
<TreeView.DataContext>
<Controles:ListaArbol/>
</TreeView.DataContext>
<TreeView.Resources>
<HierarchicalDataTemplate ItemsSource="{Binding Children}" DataType="{x:Type Controles:ListaArbol}" >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Imagen}" Stretch="Fill" Width="30" Height="30" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Text="{Binding texto}" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
Class that is binded:
public class ListaArbol: TreeViewItemBase
{
public ListaArbol()
{
this.Children = new ObservableCollection<ListaArbol>();
}
public string texto { get; set; }
public string Imagen { get; set; }
public string Control { get; set; }
public ObservableCollection<ListaArbol> Children { get; set; }
}
The previous class is derived from:
public class TreeViewItemBase : INotifyPropertyChanged
{
.....
}
and to load the tree I do something like this:
List<ListaArbol> items = new List<ListaArbol>();
ListaArbol i1 = new ListaArbol { texto = "Archivos", Imagen = "Imagenes/blue-folder-vector.png", Control="ControlArchivos" };
ListaArbol i2 = new ListaArbol { texto = "Consultas", Imagen = "Imagenes/consultas.jpg", Control= "ControlConsultas" };
items.Add(i1);
items.Add(i2);
treeView2.ItemsSource = items;