开发者

Smooth transition from image to image

Here is my XAML:

<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate>
      <Image x:Name="Expander_Normal"
             Source="/Images/arrow-e.tiff" Width="13" Height开发者_开发知识库="13" />
      <ControlTemplate.Triggers>
        <Trigger Property="ToggleButton.IsChecked" Value="True">
          <Setter x:Name="Expander_Expanded"
                  TargetName="Expander_Normal" Property="Source"
                  Value="/Images/arrow-s.tiff" />
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </Setter.Value>
</Setter>

The transition from image to another image is very rough and I don't really like it. So how can I make the transitions smooth.

UPDATE:

Maybe instead of changing the image, maybe ROTATE the image. The main image looks like >. So maybe rotate it down (90 degrees clockwise)


If you want to go fancy, you could:

  1. Add a story board
  2. Use a double animation on opacity to fade out the image box
  3. Change the image
  4. Use another double animation to fade in the image box

UPDATE

To rotate the image:

  1. Add a rotate transform to the image
  2. Use a double animation on the rotate transform's angle property

See http://www.vbforums.com/showthread.php?t=555120 for an example


Try this:

<Grid>
    <Image Source="Image1.png"
           Height="100" Width="100">
        <Image.Triggers>
            <EventTrigger RoutedEvent="MouseEnter">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                            BeginTime="0:0:0"
                            Duration="0:0:0.5"
                            From="1"
                            To="0"
                            Storyboard.TargetProperty="(Image.Opacity)"
                            />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="MouseLeave">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                            BeginTime="0:0:0"
                            Duration="0:0:0.8"
                            From="0"
                            To="1"
                            Storyboard.TargetProperty="(Image.Opacity)"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Image.Triggers>
    </Image>
    <Image Source="Image2.png"
           Height="100" Width="100" Opacity="0">
        <Image.Triggers>
            <EventTrigger RoutedEvent="MouseEnter">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                            BeginTime="0:0:0"
                            Duration="0:0:0.5"
                            From="0"
                            To="1"
                            Storyboard.TargetProperty="(Image.Opacity)"
                            />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="MouseLeave">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                            BeginTime="0:0:0"
                            Duration="0:0:0.8"
                            From="1"
                            To="0"
                            Storyboard.TargetProperty="(Image.Opacity)"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Image.Triggers>
    </Image>
</Grid>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜