Hi I'm trying to bind the visibility using a trigger, visibility should be hidden when the image object is null.
<Style TargetType="{x:Type local:DirectoryTreeView}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:DirectoryTreeView}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<TreeView Name="PART_DirectoryTree">
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding StartExpanded}"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Source, Source=Icon}">
<Setter Property="Visibility" Value="Hidden"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<Image Name="Icon" Width="16" Height="16" Source="{Binding Image}"/>
<TextBlock Text=" "></TextBlock>
<TextBlock Text="{Binding HeaderText}"></TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
So far i've tried both a trigger and a datatrigger, the first time I tried using the targetname property on the setter in the datatrigger, but then I got a compiler error.
Not working ==>
<datatrigger binding={binding Image}>
<setter targetname="Icon" property="Visibility" value="Hidden"/>
</datatrigger>
Anybody that can tell me how this binding needs to be done properly?
Image=null
? – Anatoliy Nikolaev