C#如何确保WPF控制的满负荷
我有一个添加了自定义行为的控件 该行为有两个从属属性:C#如何确保WPF控制的满负荷,c#,wpf,dependency-properties,C#,Wpf,Dependency Properties,我有一个添加了自定义行为的控件 该行为有两个从属属性: 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, bi
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中的某个对象。
问题是Handle属性的OnHandleChanged
在行为为的控件完全加载之前被激活,这会在尝试向控件添加HwndHost时引发异常。
在尝试添加HwndHost之前,如何确保控件已完全加载?
注意:尝试使用onatached()
,但无效…尝试以下操作:
public MyControl()
{
this.Loaded += MyControl_Loaded;
}
private void MyControl_Loaded(object sender, RoutedEventArgs e)
{
// Control is full loaded
}
如何实现
onhandlechange
?[…]引发异常[…]非常具体的错误描述。-那么这是什么意思呢?我得到的错误是:“BuildWindowCore未能返回托管的子窗口句柄。”当我尝试构建HandleRef:handleRefHandle=new HandleRef(这个,Player.handle);一切正常,但当我尝试将其返回到方法时失败。Yeah Loaded event在UserControl完全加载时被激发。我无法使用加载的事件,因为当我需要知道是否加载了AssociatedObject,以及当我写入:AssociatedObject.Loaded+=AssociatedObject\u Loaded;在行为的ctor中,AssociatedObject尚未创建,它为null。