开发者

Trigger on Image inside a Button WPF

I w开发者_JAVA百科ant 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


  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>


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜