0

我试图在单击按钮时更改图像的可见性,但随后图像消失并将其可见性更改回隐藏。基本上是一个保存图像,让用户知道保存成功。我只想在 xaml 中执行此操作。有什么建议吗?

代码:

<Image x:Name="SavedImage"
       Source="/check.ico">
  <Image.Resources>
    <Style TargetType="Image">
      <Style.Triggers>
        <DataTrigger Binding="{Binding ElementName=SaveDocumentsButton, Path=IsPressed}"
                     Value="True">
          <Setter Property="Visibility"
                  Value="Visible"></Setter>
        </DataTrigger>
        <Trigger Property="Image.Visibility"
                 Value="Visible">
          <Trigger.EnterActions>
            <BeginStoryboard>
              <Storyboard x:Name="saveStoryBoard">
                <DoubleAnimation x:Name="z"
                                 BeginTime="0:0:0"
                                 Duration="0:0:3"
                                 From="1.0"
                                 To="0.0"
                                 Storyboard.TargetProperty="Opacity" />
              </Storyboard>
            </BeginStoryboard>
          </Trigger.EnterActions>
        </Trigger>
      </Style.Triggers>
    </Style>
  </Image.Resources>
</Image>
<Button x:Name="SaveDocumentsButton"
        Style="{StaticResource SaveButtonWhite}"
        Command="{Binding SaveUnitCommand}"
        HorizontalAlignment="Right">
</Button>
4

1 回答 1

0

这应该很好地工作:

<Grid>
  <Image x:Name="SavedImage"
         Source="http://i.msdn.microsoft.com/dn166920.cover_lrg(en-us,MSDN.10).jpg">
    <Image.Resources>
      <Style TargetType="Image">
        <Style.Triggers>
          <DataTrigger Binding="{Binding ElementName=SaveDocumentsButton, Path=IsPressed}"
                       Value="True">
            <Setter Property="Opacity"
                    Value="1"></Setter>

            <DataTrigger.EnterActions>

              <BeginStoryboard>
                <Storyboard x:Name="saveStoryBoard">
                  <DoubleAnimation x:Name="z"
                                   BeginTime="0:0:0"
                                   Duration="0:0:3"
                                   From="1.0"
                                   To="0.0"
                                   Storyboard.TargetProperty="Opacity" />
                </Storyboard>
              </BeginStoryboard>
            </DataTrigger.EnterActions>
          </DataTrigger>

        </Style.Triggers>
      </Style>
    </Image.Resources>
  </Image>
  <Button x:Name="SaveDocumentsButton"
          Content="TEST"
          HorizontalAlignment="Right">
  </Button>
</Grid>
于 2013-04-17T17:48:32.747 回答