【问题标题】:C# how to make image move on Y axis like in slots (WPF)C#如何使图像在Y轴上像插槽一样移动(WPF)
【发布时间】:2016-05-14 12:10:36
【问题描述】:

如何让图像在 Y 轴上像插槽一样从上到下移动? 我有我的 WPF 这个:

<Border BorderBrush="Black" Margin="62,97,398,128.6" BorderThickness="2" Name="border" >
                    <Grid>
                        <Image Name="obrazekAutomat1" Source="cisla/2.png"/>
                    </Grid>
</Border>

我更喜欢在 CodeBehind 中使用它。但我想如果你给我 XAML,我可以用 C# 重写它。

谢谢:)

【问题讨论】:

    标签: c# wpf image axis slots


    【解决方案1】:

    这应该作为后面的代码工作,this 是您的控件

    this.RenderTransform = new TranslateTransform();
    
    ((TranslateTransform) this.RenderTransform).BeginAnimation(TranslateTransform.YProperty,
        new DoubleAnimation(-100, 100, TimeSpan.FromMilliseconds(1000)));
    

    【讨论】:

    • 酷就是我想要的。但我有最后一个问题:我怎样才能让图片的一部分在离开边界时消失?屏幕:beta.ctrlv.cz/qITU
    • @LukasSeidler 将 包裹在 中,然后将 Cavnas.ClipToBound 属性设置为 true,这样就可以了
    【解决方案2】:

    与其他所有控件一样,Image Control 具有 RenderTransform 属性,您可以使用 WPF 或 C# 代码设置该属性,并最终使用双动画为其“Y”属性设置动画。

    这些链接将帮助您添加翻译转换并为其设置动画:

    http://www.c-sharpcorner.com/uploadfile/mahesh/translatetransform-in-wpf/

    http://www.codeproject.com/Articles/23257/Beginner-s-WPF-Animation-Tutorial

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 2023-03-08
      • 2012-09-02
      • 1970-01-01
      • 2013-10-27
      • 2016-02-23
      • 2017-01-15
      相关资源
      最近更新 更多