使用动态属性值的ExtendedVisualStateManager和UseFluidLayout会出错 [英] ExtendedVisualStateManager and UseFluidLayout using dynamic property values gives an error

查看:51
本文介绍了使用动态属性值的ExtendedVisualStateManager和UseFluidLayout会出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改其中一个项目的代码后面的状态值(宽度和高度)。我第一次访问properrerties一切正常,但在从一个状态转到另一个状态(使用VisualStateManager.GoToState())后,属性
不能再被更改。

I want to change the values (width and height) for a state in code behind for one of my projects. The first time I access th propererties everything works just fine, but after going from one state to another (with VisualStateManager.GoToState()) the properties can no longer be changed.

当我使用States和DoubleAnimation模拟问题时没有问题,但是当我激活FluidLayout时它出错了。这是代码:

When I simulate the problem using States and DoubleAnimation there is no problem, but when I activate FluidLayout it goes wrong. Here is the code:


<Grid x:Name="LayoutRoot" Background="White">
		<VisualStateManager.VisualStateGroups>
			<VisualStateGroup x:Name="VisualStateGroup" ei:ExtendedVisualStateManager.UseFluidLayout="True">
				<VisualStateGroup.Transitions>
					<VisualTransition GeneratedDuration="0:0:1"/>
				</VisualStateGroup.Transitions>
				<VisualState x:Name="VisualStateDefault"/>
				<VisualState x:Name="VisualStateSized">
					<Storyboard>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="MyRect1">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<System:Double>0</System:Double>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="MyRect1">
							<DiscreteObjectKeyFrame KeyTime="0">
								<DiscreteObjectKeyFrame.Value>
									<System:Double>0</System:Double>
								</DiscreteObjectKeyFrame.Value>
							</DiscreteObjectKeyFrame>
						</ObjectAnimationUsingKeyFrames>
					</Storyboard>
				</VisualState>
			</VisualStateGroup>
		</VisualStateManager.VisualStateGroups>
		<VisualStateManager.CustomVisualStateManager>
			<ei:ExtendedVisualStateManager/>
		</VisualStateManager.CustomVisualStateManager>
		<Rectangle x:Name="MyRect1" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Stroke="Black" VerticalAlignment="Top" Width="100" Margin="8,8,0,0"/>
    <Button Content="Button1" Height="23" HorizontalAlignment="Left" Margin="12,251,0,0" x:Name="Button1" VerticalAlignment="Top" Width="75" />
    <Button Content="Button2" Height="23" HorizontalAlignment="Left" Margin="93,251,0,0" x:Name="Button2" VerticalAlignment="Top" Width="75" />
  </Grid>

推荐答案

FluidLayout删除了故事板在那里,创建新的,并将它们设置在标记为内部的属性上,因此无法访问新的故事板。  但是可能对你有用的一种解决方法是在将时间轴移动到新故事板之前保存对
的引用,并使用这些引用来修改关键帧。

FluidLayout removes the storyboards that were there, creates new ones, and sets them on a property that is marked internal, so there is no way to access the new storyboard.   But one workaround that might work for you is to save a reference to the timelines before they get moved to the new storyboard, and use those references to modify the keyframes.


	Public DynamicTimeline0 As ObjectAnimationUsingKeyFrames
	Public DynamicTimeline1 As ObjectAnimationUsingKeyFrames

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click

		If DynamicTimeline0 Is Nothing Then
			DynamicTimeline0 = CType(VisualStateSized.Storyboard.Children(0), ObjectAnimationUsingKeyFrames)
			DynamicTimeline1 = CType(VisualStateSized.Storyboard.Children(1), ObjectAnimationUsingKeyFrames)
		End If

		DynamicTimeline0.KeyFrames(0).Value = CType(500, Double)
		DynamicTimeline1.KeyFrames(0).Value = CType(500, Double)

		VisualStateManager.GoToState(Me, "VisualStateSized", True)
	End Sub


这篇关于使用动态属性值的ExtendedVisualStateManager和UseFluidLayout会出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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