views:

25

answers:

2

I want to control the visibility of the image in a button, via a trigger:

<Button x:Name="NotesPanel" Command="{Binding AddDocument}">
   <Image x:Name="notesImage" Source="Notes.png" Height="32"></Image>
</Button>

1/Should the trigger appear in the button or in container that countains the button ?

2/How to set the visibility of the image only ? Thanks jon

A: 
  1. I believe it can be either\or - personally, I'd probably put it in the button.
  2. Something like should work

.

<Image...>
  <Image.Style>
    <Style TargetType={x:Type Image}>
      <Style.Triggers>
        <Setter Property="Visibility" Value="Collapsed" />
        <DataTrigger Binding={Binding YourTriggerProperty} Value="true">
          <Setter Property="Visibility" Value="Visible" />
        </DataTrigger>
      </Style.Triggers>
    </Style>
  </Image.Style>
</Image>
cristobalito
A: 

Since you're updating the Visibility property of the Image, it should lie with the Image (as part of the Image's style). e.g. if the Image is hidden by default, I can choose to make it visible when the ToggleProperty is 1 by using the following trigger.

    <DataTrigger Binding="{Binding ToggleProperty}" Value="1">
        <Setter Property="Visibility" Value="Visible"/>
    </DataTrigger>
Gishu