SplitOpenThemeAnimation 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示使用 拆分 动画显示目标 UI 的预配置动画。
public ref class SplitOpenThemeAnimation sealed : Timeline
/// [Windows.Foundation.Metadata.Activatable(65536, "Microsoft.UI.Xaml.WinUIContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class SplitOpenThemeAnimation final : Timeline
[Windows.Foundation.Metadata.Activatable(65536, "Microsoft.UI.Xaml.WinUIContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class SplitOpenThemeAnimation : Timeline
Public NotInheritable Class SplitOpenThemeAnimation
Inherits Timeline
<SplitOpenThemeAnimation .../>
- 继承
- 属性
示例
下面是使用拆分打开和拆分关闭主题动画的自定义控件的示例。
// Themes/Generic.xaml
<!-- Example template of a custom control that uses split open
and split close theme animations. -->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BlankApp1">
<Style TargetType="local:SplitOpenControl" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:SplitOpenControl">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="OpenStates">
<VisualState x:Name="Open">
<Storyboard>
<SplitOpenThemeAnimation
OpenedTargetName="contentBorder"
ContentTargetName="content"
ClosedTargetName="targetRect"
ContentTranslationDirection="Left"
ContentTranslationOffset="200"
OffsetFromCenter="0"
OpenedLength="200"
ClosedLength="0"/>
<DoubleAnimation
Storyboard.TargetName="targetRect"
Storyboard.TargetProperty="Opacity"
To="0"
Duration="0"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Closed">
<Storyboard>
<SplitCloseThemeAnimation
OpenedTargetName="contentBorder"
ContentTargetName="content"
ClosedTargetName="targetRect"
ContentTranslationDirection="Left"
ContentTranslationOffset="-200"
OffsetFromCenter="0"
OpenedLength="200"
ClosedLength="0"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="targetRect" Width="100" Height="100" Fill="Blue"/>
<Popup IsOpen="False" Height="50" Width="200" x:Name="contentPopup">
<Border x:Name="contentBorder" BorderBrush="Orange" BorderThickness="3">
<TextBlock x:Name="content" Text="Hello, World!" FontSize="20"/>
</Border>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
public sealed class SplitOpenControl : Control
{
private Popup _contentPopup;
public SplitOpenControl()
{
this.DefaultStyleKey = typeof(SplitOpenControl);
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
_contentPopup = GetTemplateChild("contentPopup") as Popup;
}
protected override void OnPointerPressed(PointerRoutedEventArgs e)
{
this.CapturePointer(e.Pointer);
_contentPopup.IsOpen = true;
VisualStateManager.GoToState(this, "Open", true);
}
protected override void OnPointerReleased(PointerRoutedEventArgs e)
{
VisualStateManager.GoToState(this, "Closed", true);
this.ReleasePointerCapture(e.Pointer);
}
}
// SplitOpenControl.h:
struct SplitOpenControl : SplitOpenControlT<SplitOpenControl>
{
SplitOpenControl(){ DefaultStyleKey(winrt::box_value(L"MyApp.SplitOpenControl")); }
void OnApplyTemplate();
void OnPointerPressed(Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e);
void OnPointerReleased(Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e);
private:
Windows::UI::Xaml::Controls::Primitives::Popup m_contentPopup;
};
// SplitOpenControl.cpp:
void SplitOpenControl::OnApplyTemplate()
{
m_contentPopup = GetTemplateChild(L"contentPopup").as<Windows::UI::Xaml::Controls::Primitives::Popup>();
}
void SplitOpenControl::OnPointerPressed(Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e)
{
CapturePointer(e.Pointer());
m_contentPopup.IsOpen(true);
Windows::UI::Xaml::VisualStateManager::GoToState(*this, L"Open", true);
}
void SplitOpenControl::OnPointerReleased(Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e)
{
Windows::UI::Xaml::VisualStateManager::GoToState(*this, L"Closed", true);
ReleasePointerCapture(e.Pointer());
}
// SplitOpenControl.h:
public ref class SplitOpenControl sealed : public Windows::UI::Xaml::Controls::Control
{
public:
SplitOpenControl();
protected:
virtual void OnApplyTemplate() override;
virtual void OnPointerPressed(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
virtual void OnPointerReleased(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
private:
Windows::UI::Xaml::Controls::Primitives::Popup ^m_contentPopup;
};
// SplitOpenControl.cpp:
SplitOpenControl::SplitOpenControl()
{
DefaultStyleKey = "MyApp.SplitOpenControl";
}
void SplitOpenControl::OnApplyTemplate()
{
m_contentPopup = static_cast<Popup^>(GetTemplateChild("contentPopup"));
}
void SplitOpenControl::OnPointerPressed(PointerRoutedEventArgs^ e)
{
CapturePointer(e->Pointer);
m_contentPopup->IsOpen = true;
VisualStateManager::GoToState(this, "Open", true);
}
void SplitOpenControl::OnPointerReleased(PointerRoutedEventArgs^ e)
{
VisualStateManager::GoToState(this, "Closed", true);
ReleasePointerCapture(e->Pointer);
}
注解
请注意,设置 Duration 属性不会影响此对象,因为持续时间是预配置的。
构造函数
SplitOpenThemeAnimation() |
初始化 SplitOpenThemeAnimation 类的新实例。 |
属性
方法
ClearValue(DependencyProperty) |
清除依赖属性的本地值。 (继承自 DependencyObject) |
GetAnimationBaseValue(DependencyProperty) |
返回为依赖属性建立的任何基值,该基值适用于动画未处于活动状态的情况。 (继承自 DependencyObject) |
GetValue(DependencyProperty) |
从 DependencyObject 返回依赖属性的当前有效值。 (继承自 DependencyObject) |
ReadLocalValue(DependencyProperty) |
如果设置了本地值,则返回依赖属性的本地值。 (继承自 DependencyObject) |
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback) |
注册一个通知函数,用于侦听此 DependencyObject 实例上特定 DependencyProperty 的更改。 (继承自 DependencyObject) |
SetValue(DependencyProperty, Object) |
设置 DependencyObject 上依赖属性的本地值。 (继承自 DependencyObject) |
UnregisterPropertyChangedCallback(DependencyProperty, Int64) |
取消以前通过调用 RegisterPropertyChangedCallback 注册的更改通知。 (继承自 DependencyObject) |
事件
Completed |
在 Storyboard 对象完成播放时发生。 (继承自 Timeline) |