如何在StoryBoard中设置z-order动画 [英] How to animate z-order in a StoryBoard

查看:86
本文介绍了如何在StoryBoard中设置z-order动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个StoryBoard,我希望在用户单击一个Rectangle的事件中以我的C#代码开始。

但作为StoryBoard动画的一部分,我想改变z-order将矩形带到网格上的其他矩形的前面。

Expression Blend 2.0 with SP1在我在时间轴上录制时不允许我这样做。
< br>如果我在时间轴上选择1.0s的时间并更改Rectangle的zorder(在时间线上录制时),那么在我关闭录制并返回查看之后,z顺序一直在变化,而不仅仅是时间轴中的一个区域。

我做错了什么?

I have a StoryBoard and I want to Begin that in my C# code in an event when the user clicks a Rectangle.

But as part of the StoryBoard animation, I want to change the z-order of the Rectangle to bring it to the front of the other Rectangles I have on the Grid.

Expression Blend 2.0 with SP1 won't allow me to do this when I'm recording on the timeline.

If I select a time at 1.0s on the timeline and change the Rectangle's zorder (while recording on the timeline), then after I turn off recording and go back and look, the z-order has changed for all times, not just that one area in the timeline.

What am I doing wrong?

推荐答案

您好MrBlackKlight,

我们必须使用Grid 。 SetZIndex(element,value)方法。请在下面找到一个样本。

-------------------------------------- -----------------------------
XAML CODE
------------- -------------------------------------------------- ----

< Window
xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns x = http://schemas.microsoft.com/winfx/2006/xaml
x Class =" rectzorder.Window1"
x 名称 =" Window"
标题 =" Window1"
宽度 =" 640" 高度 =" 480">

Hi MrBlackKlight,

We have to use Grid.SetZIndex(element,value) method. Please find below a sample.

-------------------------------------------------------------------
XAML CODE
-------------------------------------------------------------------

<Window
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
x:Class="rectzorder.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">

< Window.Triggers > < / Window.Triggers >

<Window.Triggers></Window.Triggers>

< 网格 x 名称 =" L ayoutRoot">
< 矩形 保证金 =" 184,112,304,0" VerticalAlignment =" Top" 高度 =" 104" 填充 ="#FFDA3131" 描边 ="#FF000000" x 名称 =" rectangle1" MouseDown =" rectangle1_MouseDown" Panel.ZIndex =" -1&qu ot; />
< 矩形 保证金 =" 264,200,232,134" 填充 ="#FF2354BD" Stroke ="#FF000000" x 名称 =" rectangle3" 面板。 ZIndex =" -1" MouseDown =" rectangle3_MouseDown" />
< 矩形 边距 =" 224,160,264,182" x 姓名 =" rectangle2" 填充 ="#FF91C22E" 描边 ="#FF000000" Panel.ZIndex =" -1" MouseDown =" rectangle2_MouseDown" /> < / 网格 >

<Grid x:Name="LayoutRoot">
<Rectangle Margin="184,112,304,0" VerticalAlignment="Top" Height="104" Fill="#FFDA3131" Stroke="#FF000000" x:Name="rectangle1" MouseDown="rectangle1_MouseDown" Panel.ZIndex="-1"/>
<Rectangle Margin="264,200,232,134" Fill="#FF2354BD" Stroke="#FF000000" x:Name="rectangle3" Panel.ZIndex="-1" MouseDown="rectangle3_MouseDown"/>
<Rectangle Margin="224,160,264,182" x:Name="rectangle2" Fill="#FF91C22E" Stroke="#FF000000" Panel.ZIndex="-1" MouseDown="rectangle2_MouseDown"/></Grid>

< / 窗口 >


--------- -------------------------------------------------- ----------------------------------
C#代码
-------- -------------------------------------------------- ------------- ----------------------

</Window>


---------------------------------------------------------------------------------------------
C# Code
---------------------------------------------------------------------------------------------

private void rectangle1_MouseDown( object < font size = 2> sender,System.Windows.Input。 MouseButtonEventArgs e)

private void rectangle1_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)

{
网格 .SetZIndex(rectangle1,1);
< font color ="#2b91af"size = 2>网格
.SetZIndex(rectangle2,0);
网格 .SetZIndex(rectangle3,-1);
}

{
Grid.SetZIndex(rectangle1, 1);
Grid.SetZIndex(rectangle2, 0);
Grid.SetZIndex(rectangle3, -1);
}

私人 void rectangle2_MouseDown( object sender,System.Windows.Input。 MouseButtonEventArgs e)

private void rectangle2_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)

{
网格 .SetZIndex(rectangle1,0);
网格 .SetZIndex(rectangle2,1);
网格 .SetZIndex(rectangle3,-1);
}

{
Grid.SetZIndex(rectangle1, 0);
Grid.SetZIndex(rectangle2, 1);
Grid.SetZIndex(rectangle3, -1);
}

private void rectangle3_MouseDown( object sender,System.Windows.Input。 MouseButtonEventArgs e)

private void rectangle3_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)

{
网格 .SetZIndex(rectangle1,-1);
Grid .SetZIndex(rectangle2, 0);
网格 .SetZIndex(rectangle3,1);
}

>希望这能回答你的问题。

{
Grid.SetZIndex(rectangle1, -1);
Grid.SetZIndex(rectangle2, 0);
Grid.SetZIndex(rectangle3, 1);
}

Hope this answers your question.


这篇关于如何在StoryBoard中设置z-order动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆