无法使用简单的VisualStateManager来使用Silverlight 3和Expression Blend [英] Can't get a simple VisualStateManager to work with Silverlight 3 and Expression Blend

查看:45
本文介绍了无法使用简单的VisualStateManager来使用Silverlight 3和Expression Blend的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,周期几天我试图找出如何使VisualStateManager在一个简单的按钮上工作。我尝试了以下教程,但由于某种原因它仍然无效。

这是我在Expression Blend中创建visualstatemanager教程后创建的代码示例br />

Hi all,

For more than a few days I'm trying to figure out how to make the VisualStateManager work on a simple button.
I tried following tutorials but for some reason it still didn't work.

Here's an example for a code I created following a tutorial on creating a visualstatemanager in Expression Blend

<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	x:Class="VisualStateManager.MainPage"
	Width="640" Height="480">

	<Grid x:Name="LayoutRoot" Background="White">
		<VisualStateManager.VisualStateGroups>
			<VisualStateGroup x:Name="VisualStateGroup">
				<VisualStateGroup.Transitions>
					<VisualTransition GeneratedDuration="00:00:03"/>
				</VisualStateGroup.Transitions>
				<VisualState x:Name="MouseOver">
					<Storyboard>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
							<EasingDoubleKeyFrame KeyTime="00:00:00" Value="152"/>
						</DoubleAnimationUsingKeyFrames>
						<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
							<EasingDoubleKeyFrame KeyTime="00:00:00" Value="5"/>
						</DoubleAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
			</VisualStateGroup>
		</VisualStateManager.VisualStateGroups>
	
		<Button x:Name="button" Height="101" Margin="174,112,204,0" VerticalAlignment="Top" Content="Button" RenderTransformOrigin="0.5,0.5">
			<Button.RenderTransform>
				<TransformGroup>
					<ScaleTransform/>
					<SkewTransform/>
					<RotateTransform/>
					<TranslateTransform/>
				</TransformGroup>
			</Button.RenderTransform>
		</Button>
	
	</Grid>
</UserControl>


这应该会移动MouseOver上的按钮,但它不起作用!

任何人都可以请帮助我这个?我做错了什么?

谢谢!
半恐怖

This is supposed to move the button on MouseOver, but it just doesn't work!

Can anyone please help me with this? What am I doing wrong?

Thanks!

Dror

推荐答案

你所做的是创造了一个视觉在网格上显示状态,并将其命名为"MouseOver"。 不幸的是,当您将鼠标悬停在布局根上时,实际上并未激活状态。

如果您希望在将鼠标悬停在按钮上时发生状态,请尝试以下操作:
1.创建您的按钮
2.右键单击它,然后选择"编辑模板 - >编辑副本"
3.默认值应该没有问题.4。现在,您应该在状态窗口中看到所有按钮的状态。您看到的状态是在控件本身上定义的。

如果您想要一些不是特定于控件的东西,您可以按照上面的方式进行,但是您需要额外的步骤来激活状态。 br /> 1.在资源面板中,选择行为类别
2.将GoToStateAction拖到要触发可视状态的对象上(例如,LayoutRoot或按钮)。您将它放在LayoutRoot上,在对象和时间轴面板中选择行为,并查看其属性
4.将EventName下拉列表设置为MouseEnter
5.将StateName下拉列表设置为"MouseOver"

希望有所帮助!
What you have done is created a visual state on the grid, and named it "MouseOver".  Unfortunately that doesn't actually activate the state when you mouse over the layout root.

If you want a state to happen when you mouse over the button, try this:
1. Create your button
2. Right click it, and select "edit template -> edit a copy"
3. The default values should be fine
4. You should now see all of the button's states in the states window. The states you see are defined on the control itself.

If you want something not specific to a control, you can do it the way you did above, but you need additional steps to activate the state.
1. In the assets panel, select the behaviors category
2. Drag a GoToStateAction onto the object you want to trigger the visual state (for example, LayoutRoot, or your button)
3. Assuming you put it on LayoutRoot, select the behavior in the objects and timeline panel, and view its properties
4. Set the EventName dropdown to MouseEnter
5. Set the StateName dropdown to be "MouseOver"
6. If you want to go back to the original state as well, add another GoToStateAction behavior with the trigger set to MouseLeave, and the StateName set to a state you have created, something like "Normal" state.  You can't go back to the base state.

Hope that helps!


这篇关于无法使用简单的VisualStateManager来使用Silverlight 3和Expression Blend的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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