我第一次玩Expression Blend。 我制作了一个非常简单的覆盖网格,占据了所有的屏幕空间。
<!-- phone application page -->
<Grid x:Name="LayoutRoot">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
</Grid>
<TextBlock Grid.Row="0" Text="Some Content" />
<TextBlock Grid.Row="1" Text="Some Other Content />
<Grid x:Name="Overlay" Grid.RowSpan="2" Background="Black" Opacity="0" Visibility="Collapsed">
<TextBlock Text="Loading..." />
<toolkit:PerformanceProgressBar x:Name="ProgressBar" IsIndeterminate="False" />
</Grid>
</Grid>
我希望覆盖网格有两种状态:
,其中 LoadingState进行:
NotLoadingState (基本上它在xaml中设置为默认值):
转换之间的时间:0.5秒
我在这样的代码隐藏中触发状态:
private void VmPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == ListViewModel.IsLoadingPropertyName)
{
if (_vm.IsLoading)
{
VisualStateManager.GoToState(this, LoadingStatePropertyName, true);
}
else
{
VisualStateManager.GoToState(this, NotLoadingStatePropertyName, true);
}
}
}
然而,就像上面的代码一样简单,我无法使转换工作。将状态更改为LoadingState工作,我得到一个很好的Opacity动画,但它没有相反(LoadingState - &gt; NotLoadingState) - 覆盖网格只是消失而没有任何动画。我猜这是因为Visibility设置为Collapsed。我一直试图在Expression Blend中提出一些东西但到目前为止没有任何工作。
这是请求生成的源:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="LoadingStateGroup">
<VisualStateGroup.Transitions>
<VisualTransition From="LoadingState" GeneratedDuration="0" To="NotLoadingState">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Overlay">
<EasingDoubleKeyFrame KeyTime="0" Value="0.8"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
</DoubleAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Overlay">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.5">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualTransition>
<VisualTransition From="NotLoadingState" GeneratedDuration="0" To="LoadingState">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Overlay">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:0.5">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Overlay">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0.795"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualTransition>
<VisualTransition GeneratedDuration="0"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="LoadingState">
<Storyboard>
<DoubleAnimation Duration="0" To="0.795" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Overlay" d:IsOptimized="True"/>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Overlay">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="NotLoadingState">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="Overlay">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Overlay" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
答案 0 :(得分:1)
您需要的是流体布局。它专门用于解决这个问题。您可以阅读更多here (good read, if a bit long),相应的示例为here。甚至还有一个Windows Phone 7特定教程over here。
答案 1 :(得分:0)
你是正确的,转换是立即将可见性切换为折叠,所以你看不到动画不透明度。
您可以在Expression Blend中执行的操作是在两个状态之间创建自定义转换,这样您就可以直接编辑转换的故事板。然后,您应该能够创建一个故事板,在过渡结束时激活可见性。
很抱歉,我无法提供有关如何使用Blend的更多指导,但我没有在此计算机上安装它。