我有一个控件,我向其中添加了自定义行为。
该行为有两个 DependencyProperties:
public SomeObject Player {
get { return (e)GetValue(PlayerProperty); }
set { SetValue(PlayerProperty, value); }
}
// Using a DependencyProperty as the backing store for Player. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PlayerProperty =
DependencyProperty.Register("Player", typeof(IVideoPlayerDTO), typeof(PlayerStreamBehavior), new UIPropertyMetadata(null));
public IntPtr Handle {
get { return (IntPtr)GetValue(HandleProperty); }
set { SetValue(HandleProperty, value); }
}
// Using a DependencyProperty as the backing store for Handle. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HandleProperty =
DependencyProperty.Register("Handle", typeof(IntPtr), typeof(PlayerStreamBehavior), new UIPropertyMetadata(IntPtr.Zero, OnHandleChanged));
每个都绑定到 WPF 中的某个对象。问题是在OnHandleChanged
具有行为的控件完全加载之前激活了 Handle 属性,这会在尝试将 HwndHost 添加到控件时引发异常。在尝试添加 HwndHost 之前,如何确保控件已完全加载?Ps: 试过用OnAttached()
,但是没用。。。