1 pièce(s) jointe(s)
Modifier le style d'un treeviewItem en Wpf
J'ai une classe :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
public class cItem
{
public string Name { get; set; }
public string FullPath { get; set; }
public bool System { get; set; }
}
public class cDirectoryItem : cItem
{
public List<cItem> Items { get; set; }
public cDirectoryItem()
{
Items = new List<cItem>();
}
public cDirectoryItem(string pName,string pFullName,List<cItem> pItems)
{
Items = new List<cItem>();
Name = pName;
FullPath = pFullName;
Items = pItems;
}
} |
Que j'utilise en binding pour mon treeview, jusque là tout va très bien :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
...
<Window.Resources>
<HierarchicalDataTemplate DataType="{x:Type Model:cDirectoryItem}"
ItemsSource="{Binding Items}">
<TextBlock Text="{Binding Path=Name}" ToolTip="{Binding Path=Path}" />
</HierarchicalDataTemplate>
</Window.Resources>
...
<TreeView Grid.Column="0" Name="trvDir" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemsSource="{Binding}"/> |
Par contre quand ma propriété "System" est à true, je voudrais changer la couleur du texte pour l'item voulu, donc j'ai essayé ceci :
Code:
1 2 3 4 5 6 7 8 9 10
|
<TreeView Grid.Column="0" Name="trvDir" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ItemsSource="{Binding}">
<Style TargetType="TreeViewItem">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=cDirectoryItem, Path=System}" Value="True">
<Setter Property="Foreground" Value="Green" />
</DataTrigger>
</Style.Triggers>
</Style>
</TreeView> |
Ce qui me donne ceci :
Pièce jointe 438418
Une idée ?