我正在开发一个 WP7 应用程序,当用户旋转到横向时,我想在应用程序的标题中隐藏一个图像,以便用户可以看到更多信息。
目前,我在 Pivot 控件的 TitleTemplate 中有图像。使用 Blend,我在横向模式下添加了一个名为“Land”的 VisualState,并且我隐藏了图像。这在 Blend 中看起来不错。当我通过 Visual Studio 运行它时,图像永远不会消失!
我的 XAML 和相关的 c# 如下。使用我找到的示例,我根据 Orientation 值的前 4 个字符派生要使用的 VisualState 的名称。
<controls:Pivot.TitleTemplate>
<DataTemplate>
<Image x:Name="headerImage" Visibility="Visible" Source="{StaticResource headerLogo}" Height="55" HorizontalAlignment="Left" >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="Land">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="headerImage">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Port"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Image>
</DataTemplate>
</controls:Pivot.TitleTemplate>
以及相关的 C# - 我已经在调试器中介入(所以它受到了打击)
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
VisualStateManager.GoToState(this, e.Orientation.ToString().Substring(0,4), false);
}
任何人都可以看到任何咆哮者吗?
谢谢