<bdo id='fACxJ'></bdo><ul id='fACxJ'></ul>

    1. <i id='fACxJ'><tr id='fACxJ'><dt id='fACxJ'><q id='fACxJ'><span id='fACxJ'><b id='fACxJ'><form id='fACxJ'><ins id='fACxJ'></ins><ul id='fACxJ'></ul><sub id='fACxJ'></sub></form><legend id='fACxJ'></legend><bdo id='fACxJ'><pre id='fACxJ'><center id='fACxJ'></center></pre></bdo></b><th id='fACxJ'></th></span></q></dt></tr></i><div id='fACxJ'><tfoot id='fACxJ'></tfoot><dl id='fACxJ'><fieldset id='fACxJ'></fieldset></dl></div>

    2. <tfoot id='fACxJ'></tfoot>
      <legend id='fACxJ'><style id='fACxJ'><dir id='fACxJ'><q id='fACxJ'></q></dir></style></legend>
      1. <small id='fACxJ'></small><noframes id='fACxJ'>

      2. 如何仅使用 c# 代码在图像对象上创建旋转动画(在 WPF 窗口内)

        时间:2023-10-06
        <legend id='hlIA8'><style id='hlIA8'><dir id='hlIA8'><q id='hlIA8'></q></dir></style></legend>
        <i id='hlIA8'><tr id='hlIA8'><dt id='hlIA8'><q id='hlIA8'><span id='hlIA8'><b id='hlIA8'><form id='hlIA8'><ins id='hlIA8'></ins><ul id='hlIA8'></ul><sub id='hlIA8'></sub></form><legend id='hlIA8'></legend><bdo id='hlIA8'><pre id='hlIA8'><center id='hlIA8'></center></pre></bdo></b><th id='hlIA8'></th></span></q></dt></tr></i><div id='hlIA8'><tfoot id='hlIA8'></tfoot><dl id='hlIA8'><fieldset id='hlIA8'></fieldset></dl></div>

        <small id='hlIA8'></small><noframes id='hlIA8'>

            1. <tfoot id='hlIA8'></tfoot>
              • <bdo id='hlIA8'></bdo><ul id='hlIA8'></ul>

                    <tbody id='hlIA8'></tbody>
                  本文介绍了如何仅使用 c# 代码在图像对象上创建旋转动画(在 WPF 窗口内)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有几个与同一类事情有关的未决问题,

                  I have a couple of open questions relating to the same sort of thing,

                  我对 WPF 很陌生,但对 C# 和 Winforms 很有经验.

                  I am quite new to WPF but experienced with C# and Winforms.

                  我在互联网上四处寻找一个可行的示例,但还没有找到一个可行的示例.

                  I have looked around on the interweb for a working example but have yet to find one that works.

                  我想要实现的是在 C# 函数中创建以下内容

                  What I want to achieve is in a C# function create the following

                  • 创建图像(图像 1)
                  • 创建图片(图片 2)
                  • 将图像并排放置在窗口中
                  • 创建故事板
                  • 将 image1 的旋转属性设置为 0 到 360 度的动画(动画 1)
                  • 将图像 2 的不透明度属性从完全变为不可见(动画 2)
                  • 故事板应该运行十秒钟,动画 1 开始0 秒,动画 2 从 5 秒开始

                  对代码的明确请求表示歉意,但是,我已经查看并尝试过,我之前的问题有完整的代码已执行但没有显示动画(下面的链接)

                  apologies for the explicit request for code, but, I have looked, and tried, my previous question had full code that executed but no animation showed (link below)

                  如何使用 c# 代码在 wpf 中创建故事板和旋转图像

                  提前致谢

                  丹.

                  推荐答案

                  这是您问题的有效 XAML 版本,后跟 C# 中的相同内容.可能不完全是你所追求的,但它应该说明它.

                  Here is a working XAML versionn of your question followed by the identical thing in C#. May not be exactly what you were after, but it should illustrate it.

                  XAML 版本:

                  <Window x:Class="WpfApplication1.MainWindow"
                          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                          Title="MainWindow" Height="350" Width="525">
                      <Window.Resources>
                          <Storyboard x:Key="Storyboard" BeginTime="00:00:00.000" Duration="00:00:10.000">
                              <DoubleAnimation Storyboard.TargetName="RotateImage" 
                                               Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)" 
                                               From="0" To="360" BeginTime="00:00:05.000" Duration="00:00:05.000" />
                              <DoubleAnimation Storyboard.TargetName="OpacityImage" 
                                               Storyboard.TargetProperty="Opacity" 
                                               From="1" To="0" Duration="00:00:10.000" />
                          </Storyboard>
                      </Window.Resources>
                      <Grid>
                          <Grid.RowDefinitions>
                              <RowDefinition />
                              <RowDefinition Height="Auto" />
                          </Grid.RowDefinitions>
                          <Grid.ColumnDefinitions>
                              <ColumnDefinition />
                              <ColumnDefinition />
                          </Grid.ColumnDefinitions>
                          <Image x:Name="RotateImage" Stretch="Uniform" Source="Chrysanthemum.jpg">
                              <Image.RenderTransform>
                                  <RotateTransform Angle="0" />
                              </Image.RenderTransform>
                          </Image>
                          <Image x:Name="OpacityImage" Grid.Column="1" Stretch="Uniform" Source="Desert.jpg" />
                          <Button Grid.Row="1" Grid.ColumnSpan="2" Content="Start">
                              <Button.Triggers>
                                  <EventTrigger RoutedEvent="Button.Click">
                                      <BeginStoryboard Storyboard="{StaticResource Storyboard}" />
                                  </EventTrigger>
                              </Button.Triggers>
                          </Button>
                      </Grid>
                  </Window>
                  

                  和C#版本:

                      public MainWindow()
                      {
                          InitializeComponent();
                  
                          Image rotateImage = new Image()
                          {
                              Stretch = Stretch.Uniform,
                              Source = new BitmapImage(new Uri("pack://application:,,,/Chrysanthemum.jpg")),
                              RenderTransform = new RotateTransform()
                          };
                          Image opacityImage = new Image()
                          {
                              Stretch = Stretch.Uniform,
                              Source = new BitmapImage(new Uri("pack://application:,,,/Desert.jpg"))
                          };
                  
                          LayoutRoot.Children.Add(rotateImage);
                          LayoutRoot.Children.Add(opacityImage);
                  
                          Grid.SetColumn(opacityImage, 1);
                  
                          Storyboard storyboard = new Storyboard();
                          storyboard.Duration = new Duration(TimeSpan.FromSeconds(10.0));
                          DoubleAnimation rotateAnimation = new DoubleAnimation()
                          {
                              From = 0,
                              To = 360,
                              Duration = storyboard.Duration
                          };
                          DoubleAnimation opacityAnimation = new DoubleAnimation()
                          {
                              From = 1.0,
                              To = 0.0,
                              BeginTime = TimeSpan.FromSeconds(5.0),
                              Duration = new Duration(TimeSpan.FromSeconds(5.0))
                          };
                  
                          Storyboard.SetTarget(rotateAnimation, rotateImage);
                          Storyboard.SetTargetProperty(rotateAnimation, new PropertyPath("(UIElement.RenderTransform).(RotateTransform.Angle)"));
                          Storyboard.SetTarget(opacityAnimation, opacityImage);
                          Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));
                  
                          storyboard.Children.Add(rotateAnimation);
                          storyboard.Children.Add(opacityAnimation);
                  
                          Resources.Add("Storyboard", storyboard);
                  
                          Button button = new Button()
                          {
                              Content = "Begin"
                          };
                          button.Click += button_Click;
                  
                          Grid.SetRow(button, 1);
                          Grid.SetColumnSpan(button, 2);
                  
                          LayoutRoot.Children.Add(button);
                      }
                  
                      void button_Click(object sender, RoutedEventArgs e)
                      {
                          ((Storyboard)Resources["Storyboard"]).Begin();
                      }
                  

                  这篇关于如何仅使用 c# 代码在图像对象上创建旋转动画(在 WPF 窗口内)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 C# 中旋转图像时如何防止剪切? 下一篇:根据旋转的文本框旋转光标

                  相关文章

                  <small id='lDvzB'></small><noframes id='lDvzB'>

                  <legend id='lDvzB'><style id='lDvzB'><dir id='lDvzB'><q id='lDvzB'></q></dir></style></legend>
                  • <bdo id='lDvzB'></bdo><ul id='lDvzB'></ul>
                  <tfoot id='lDvzB'></tfoot>
                    <i id='lDvzB'><tr id='lDvzB'><dt id='lDvzB'><q id='lDvzB'><span id='lDvzB'><b id='lDvzB'><form id='lDvzB'><ins id='lDvzB'></ins><ul id='lDvzB'></ul><sub id='lDvzB'></sub></form><legend id='lDvzB'></legend><bdo id='lDvzB'><pre id='lDvzB'><center id='lDvzB'></center></pre></bdo></b><th id='lDvzB'></th></span></q></dt></tr></i><div id='lDvzB'><tfoot id='lDvzB'></tfoot><dl id='lDvzB'><fieldset id='lDvzB'></fieldset></dl></div>