【问题标题】:How to set DependencyProperty.UnsetValue in VisualState Storyboard in WinRT app?如何在 WinRT 应用程序的 VisualState Storyboard 中设置 DependencyProperty.UnsetValue?
【发布时间】:2015-06-17 11:37:06
【问题描述】:

我正在开发 Windows 8.1 应用商店应用程序,在一个页面上我需要在横向模式下设置 MyControl.Width = 450,但在纵向模式下我希望控件伸展到所有可用空间。 作为一种解决方法,可以使用 Horizo​​ntalAlighment Right vs Stretch with MinWidth,但我对 VisualState Storyboards 的解决方案感兴趣。

使用 ObjectAnimationUsingKeyFrames 很容易设置特定的宽度,如下所示:

<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="MyControl" Storyboard.TargetProperty="Width">
    <DiscreteObjectKeyFrame KeyTime="0" Value="450" />
</ObjectAnimationUsingKeyFrames>

但我不知道如何在此处设置 DependencyProperty.UnsetValue,换句话说,将属性设置为默认的未设置值。注意我正在寻找 Windows 8.1 应用程序中的解决方案。在 WPF XAML 中可能很容易实现,但在 Windows 8.1 XAML 中有点受限。谢谢

【问题讨论】:

  • 您可以在后面的代码中使用“Page_SizeChanged”事件来实现。

标签: xaml windows-runtime winrt-xaml visualstatemanager


【解决方案1】:

这个 sn-p 看起来像单个 VisualState 的内容。同一个 VisualStateGroup 中的每个 VisualState 将是互斥的。如果您有一种状态不修改与该状态相同的 VisualStateGroup 中的 Width 属性,那么您应该能够在两者之间进行 GoToState 并有效地设置/取消设置值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-03
    • 2018-02-03
    • 1970-01-01
    相关资源
    最近更新 更多