Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 不确定动画应该使用哪个属性_C#_Xaml_Animation_Storyboard_Winrt Xaml - Fatal编程技术网

C# 不确定动画应该使用哪个属性

C# 不确定动画应该使用哪个属性,c#,xaml,animation,storyboard,winrt-xaml,C#,Xaml,Animation,Storyboard,Winrt Xaml,我正在Windows 8中创建一个kiosk应用程序,但它将在8.1中用作分配访问应用程序。我想创建一个广告动画。动画的想法是附加在这个线程作为图像。基本上会有6-10个L形的图像(右侧为一列,底部为一行)。现在,右下角的一则广告将静止不动。列中的广告将像HTML的字幕一样遍历并到达行,此时行中的广告将遍历并到达列。这样的话,广告就会以一种时钟模式不断移动。如何在我的C#/XAML应用程序中实现这一点 请不要把广告放在上面或左边。广告是&来源是互联网URL。所有广告都在ItemsControl中

我正在Windows 8中创建一个kiosk应用程序,但它将在8.1中用作分配访问应用程序。我想创建一个广告动画。动画的想法是附加在这个线程作为图像。基本上会有6-10个L形的图像(右侧为一列,底部为一行)。现在,右下角的一则广告将静止不动。列中的广告将像HTML的字幕一样遍历并到达行,此时行中的广告将遍历并到达列。这样的话,广告就会以一种时钟模式不断移动。如何在我的C#/XAML应用程序中实现这一点

请不要把广告放在上面或左边。广告是
&来源是互联网URL。所有广告都在
ItemsControl


哎呀,让我们从我有多讨厌这个应用开始吧

现在开始回答。

void Move()
{
    var ads = new Rectangle[] { Ad1, Ad2, Ad3, Ad4, Ad5, Ad6, Ad7 };
    foreach (var item in ads)
    {
        var row = (int)item.GetValue(Grid.RowProperty);
        var col = (int)item.GetValue(Grid.ColumnProperty);
        var x = item.ActualWidth;
        var y = item.ActualHeight;

        // bottom
        if (row == 3)
        {
            // left-last
            if (col == 0)
            {
                row = 0;
                col = 3;
                x = -x;
                y = 0;
            }
            // others
            else
            {
                col--;
                x = -x;
                y = 0;
            }
        }
       // right
       else
        {
           // bottom-last
           if (row == 2)
            {
                row = 3;
                col = 2;
                x = -x;
            }
            else
            {
                row++;
                x = 0;
            }
        }

        var dr = new Duration(TimeSpan.FromSeconds(.5));
        var tx = item.RenderTransform = new TranslateTransform();

        var ax = new DoubleAnimation { To = x, Duration = dr };
        Storyboard.SetTarget(ax, tx);
        Storyboard.SetTargetProperty(ax, "X");

        var ay = new DoubleAnimation { To = y, Duration = dr };
        Storyboard.SetTarget(ay, tx);
        Storyboard.SetTargetProperty(ay, "Y");

        var st = new Storyboard { FillBehavior = FillBehavior.HoldEnd };
        st.Children.Add(ax);
        st.Children.Add(ay);
        st.Completed += (s, e) =>
        {
            item.SetValue(Grid.RowProperty, row);
            item.SetValue(Grid.ColumnProperty, col);
            st.Stop();
        };
        st.Begin();
    }
}
我不认为你真的需要动画。你很可能只会每隔一段时间更换一次广告。他们的立场只要简单地改变,而不是转变,似乎就足够了

试试这个:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Rectangle Fill="White" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" Grid.RowSpan="3" />
    <Rectangle x:Name="Ad1" Fill="Green" Grid.Column="3" Grid.Row="3" />
    <Rectangle x:Name="Ad2" Fill="IndianRed" Grid.Column="0" Grid.Row="3" />
    <Rectangle x:Name="Ad3" Fill="Red" Grid.Column="1" Grid.Row="3" />
    <Rectangle x:Name="Ad4" Fill="DarkRed" Grid.Column="2" Grid.Row="3" />
    <Rectangle x:Name="Ad5" Fill="Pink" Grid.Column="3" Grid.Row="0" />
    <Rectangle x:Name="Ad6" Fill="HotPink" Grid.Column="3" Grid.Row="1" />
    <Rectangle x:Name="Ad7" Fill="Purple" Grid.Column="3" Grid.Row="2" />
</Grid>
对我来说,它看起来很不错

但是如果你必须有动画,试试这个。

void Move()
{
    var ads = new Rectangle[] { Ad1, Ad2, Ad3, Ad4, Ad5, Ad6, Ad7 };
    foreach (var item in ads)
    {
        var row = (int)item.GetValue(Grid.RowProperty);
        var col = (int)item.GetValue(Grid.ColumnProperty);
        var x = item.ActualWidth;
        var y = item.ActualHeight;

        // bottom
        if (row == 3)
        {
            // left-last
            if (col == 0)
            {
                row = 0;
                col = 3;
                x = -x;
                y = 0;
            }
            // others
            else
            {
                col--;
                x = -x;
                y = 0;
            }
        }
       // right
       else
        {
           // bottom-last
           if (row == 2)
            {
                row = 3;
                col = 2;
                x = -x;
            }
            else
            {
                row++;
                x = 0;
            }
        }

        var dr = new Duration(TimeSpan.FromSeconds(.5));
        var tx = item.RenderTransform = new TranslateTransform();

        var ax = new DoubleAnimation { To = x, Duration = dr };
        Storyboard.SetTarget(ax, tx);
        Storyboard.SetTargetProperty(ax, "X");

        var ay = new DoubleAnimation { To = y, Duration = dr };
        Storyboard.SetTarget(ay, tx);
        Storyboard.SetTargetProperty(ay, "Y");

        var st = new Storyboard { FillBehavior = FillBehavior.HoldEnd };
        st.Children.Add(ax);
        st.Children.Add(ay);
        st.Completed += (s, e) =>
        {
            item.SetValue(Grid.RowProperty, row);
            item.SetValue(Grid.ColumnProperty, col);
            st.Stop();
        };
        st.Begin();
    }
}

祝你好运

恶心,让我们从我有多讨厌这个应用开始吧

现在开始回答。

void Move()
{
    var ads = new Rectangle[] { Ad1, Ad2, Ad3, Ad4, Ad5, Ad6, Ad7 };
    foreach (var item in ads)
    {
        var row = (int)item.GetValue(Grid.RowProperty);
        var col = (int)item.GetValue(Grid.ColumnProperty);
        var x = item.ActualWidth;
        var y = item.ActualHeight;

        // bottom
        if (row == 3)
        {
            // left-last
            if (col == 0)
            {
                row = 0;
                col = 3;
                x = -x;
                y = 0;
            }
            // others
            else
            {
                col--;
                x = -x;
                y = 0;
            }
        }
       // right
       else
        {
           // bottom-last
           if (row == 2)
            {
                row = 3;
                col = 2;
                x = -x;
            }
            else
            {
                row++;
                x = 0;
            }
        }

        var dr = new Duration(TimeSpan.FromSeconds(.5));
        var tx = item.RenderTransform = new TranslateTransform();

        var ax = new DoubleAnimation { To = x, Duration = dr };
        Storyboard.SetTarget(ax, tx);
        Storyboard.SetTargetProperty(ax, "X");

        var ay = new DoubleAnimation { To = y, Duration = dr };
        Storyboard.SetTarget(ay, tx);
        Storyboard.SetTargetProperty(ay, "Y");

        var st = new Storyboard { FillBehavior = FillBehavior.HoldEnd };
        st.Children.Add(ax);
        st.Children.Add(ay);
        st.Completed += (s, e) =>
        {
            item.SetValue(Grid.RowProperty, row);
            item.SetValue(Grid.ColumnProperty, col);
            st.Stop();
        };
        st.Begin();
    }
}
我不认为你真的需要动画。你很可能只会每隔一段时间更换一次广告。他们的立场只要简单地改变,而不是转变,似乎就足够了

试试这个:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Rectangle Fill="White" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" Grid.RowSpan="3" />
    <Rectangle x:Name="Ad1" Fill="Green" Grid.Column="3" Grid.Row="3" />
    <Rectangle x:Name="Ad2" Fill="IndianRed" Grid.Column="0" Grid.Row="3" />
    <Rectangle x:Name="Ad3" Fill="Red" Grid.Column="1" Grid.Row="3" />
    <Rectangle x:Name="Ad4" Fill="DarkRed" Grid.Column="2" Grid.Row="3" />
    <Rectangle x:Name="Ad5" Fill="Pink" Grid.Column="3" Grid.Row="0" />
    <Rectangle x:Name="Ad6" Fill="HotPink" Grid.Column="3" Grid.Row="1" />
    <Rectangle x:Name="Ad7" Fill="Purple" Grid.Column="3" Grid.Row="2" />
</Grid>
对我来说,它看起来很不错

但是如果你必须有动画,试试这个。

void Move()
{
    var ads = new Rectangle[] { Ad1, Ad2, Ad3, Ad4, Ad5, Ad6, Ad7 };
    foreach (var item in ads)
    {
        var row = (int)item.GetValue(Grid.RowProperty);
        var col = (int)item.GetValue(Grid.ColumnProperty);
        var x = item.ActualWidth;
        var y = item.ActualHeight;

        // bottom
        if (row == 3)
        {
            // left-last
            if (col == 0)
            {
                row = 0;
                col = 3;
                x = -x;
                y = 0;
            }
            // others
            else
            {
                col--;
                x = -x;
                y = 0;
            }
        }
       // right
       else
        {
           // bottom-last
           if (row == 2)
            {
                row = 3;
                col = 2;
                x = -x;
            }
            else
            {
                row++;
                x = 0;
            }
        }

        var dr = new Duration(TimeSpan.FromSeconds(.5));
        var tx = item.RenderTransform = new TranslateTransform();

        var ax = new DoubleAnimation { To = x, Duration = dr };
        Storyboard.SetTarget(ax, tx);
        Storyboard.SetTargetProperty(ax, "X");

        var ay = new DoubleAnimation { To = y, Duration = dr };
        Storyboard.SetTarget(ay, tx);
        Storyboard.SetTargetProperty(ay, "Y");

        var st = new Storyboard { FillBehavior = FillBehavior.HoldEnd };
        st.Children.Add(ax);
        st.Children.Add(ay);
        st.Completed += (s, e) =>
        {
            item.SetValue(Grid.RowProperty, row);
            item.SetValue(Grid.ColumnProperty, col);
            st.Stop();
        };
        st.Begin();
    }
}

祝你好运

您可以使用动画,在其中为元素的x和y属性设置动画。在您的情况下,必须定义4个关键帧:一个用于从顶部进入,一个用于移动到底部,一个用于在对角线上移动,一个用于在左侧向外移动。然后你从头开始重复动画我没有固定数量的广告,那我该怎么办?我认为每个图像的X&Y都会有所不同。对于X&Y,您可以延迟动画。但是我不认为只有通过xaml你才能做你想做的事情,我认为最好创建一个新的自定义用户控件来完成广告展示工作。使用c#在那里+1,我正要用路径显示一些
PathListBox
DoubleAnimationUsingPath
的答案,直到我意识到RT/W8没有这些选项,所以对此会很好奇,我可能也会给它一笔赏金,因为我知道我将来也会遇到这个问题。问得好。你可以使用一个动画来设置元素的x和y属性的动画。在您的情况下,必须定义4个关键帧:一个用于从顶部进入,一个用于移动到底部,一个用于在对角线上移动,一个用于在左侧向外移动。然后你从头开始重复动画我没有固定数量的广告,那我该怎么办?我认为每个图像的X&Y都会有所不同。对于X&Y,您可以延迟动画。但是我不认为只有通过xaml你才能做你想做的事情,我认为最好创建一个新的自定义用户控件来完成广告展示工作。使用c#在那里+1,我正要用路径显示一些
PathListBox
DoubleAnimationUsingPath
的答案,直到我意识到RT/W8没有这些选项,所以对此会很好奇,我可能也会给它一笔赏金,因为我知道我将来也会遇到这个问题。好问题。是的,我希望杰瑞一定会帮我。谢谢你,伙计。我喜欢第二个解决方案,那就是动画。但是有可能有平滑的恒定动画吗?我注意到在故事板完成后有一个小站。有没有可能创建一个像新闻播报员一样的动画?同样,讨厌这个应用程序。只需调整计时,使动画和timer.tick相同。(或接近相同,将需要一些调整)否则,可能需要查看Charles Petzold的AnimationAlongPath(或其他内容)。不是简单的,只是想另一种方法。因为这些只是图像。您可以轻松地将scrollviewer垂直和水平放置在UI中,只需设置水平偏移的动画即可。这应该是可行的,但需要你在每个观众中有2倍多的广告,这也意味着你将有4倍多的广告,因为它们将在两个位置。是的,我希望杰瑞一定会帮助我。谢谢你,伙计。我喜欢第二个解决方案,那就是动画。但是有可能有平滑的恒定动画吗?我注意到在故事板完成后有一个小站。有没有可能创建一个像新闻播报员一样的动画?同样,讨厌这个应用程序。只需调整计时,使动画和timer.tick相同。(或接近相同,将需要一些调整)否则,可能需要查看Charles Petzold的AnimationAlongPath(或其他内容)。不是简单的,只是想另一种方法。因为这些只是图像。您可以轻松地将scrollviewer垂直和水平放置在UI中,只需设置水平偏移的动画即可。它应该可以工作,但需要在每个观众中有2倍多的广告,这也意味着你将有4倍多的广告,因为它们将在两个位置。