我创建了一个问题,我想将控件绑定到 windowsFormsHost 控件。但是众所周知,Child属性不是 DP,所以我创建了一个包装器。
/// <summary>
/// Bindable version of windows form hosts
/// </summary>
public class BindableWindowsFormsHost : WindowsFormsHost
{
/// <summary>
/// Max value of the textbox
/// </summary>
public Control BindableChild
{
get { return (Control)GetValue(BindableChildProperty); }
set
{
SetValue(BindableChildProperty, value);
}
}
// Using a DependencyProperty as the backing store for Max. This enables animation, styling, binding, etc...
public static readonly DependencyProperty BindableChildProperty =
DependencyProperty.Register("BindableChild", typeof(Control), typeof(BindableWindowsFormsHost), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnBindableChildChanged)));
/// <summary>
/// Handles changes to the FlyoutWindowSize property.
/// </summary>
private static void OnBindableChildChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((WindowsFormsHost)d).Child = e.NewValue as Control;
}
}
e.NewValue 获得了我想要的控件并正确设置它,但我没有看到更改被反映。孩子已设置,但无法看到带有新控件的 windowsFormsHost。
有人知道吗?
谢谢和问候, Kev84