我有一个win32窗口,我在WPF窗口中托管,我需要在该窗口的顶部放置另一个控件(类似于视频和字幕在它上面) 但由于某种原因,我没有看到我放在窗户上的控制。 这是我到目前为止所得到的:
<Grid>
<Border Name="ControlHostElement" Background="Black" SizeChanged="ControlHostElement_SizeChanged" />
<View:MospView />
</Grid>
VideoHostControl
是HwndHost
类
public static readonly DependencyProperty VideoWindowProperty =
DependencyProperty.Register("VideoWindow", typeof(IntPtr), typeof(VideoView),
new FrameworkPropertyMetadata(IntPtr.Zero, new PropertyChangedCallback(VideoWindowChanged)));
public IntPtr VideoWindow
{
get { return (IntPtr)GetValue(VideoWindowProperty); }
set { SetValue(VideoWindowProperty, value); }
}
private static void VideoWindowChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
VideoView view = sender as VideoView;
if (view == null) return;
view.ControlHostElement.Child = view.VideoHost = new VideoHostControl(view.VideoWindow);
view.ControlHostElement_SizeChanged(sender, null);
}
private void ControlHostElement_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (VideoHost != null)
{
double width = viewBoxWraper.ActualWidth * ControlHostElement.ActualWidth / grid.ActualWidth;
double height = viewBoxWraper.ActualHeight * ControlHostElement.ActualHeight / grid.ActualHeight;
VideoHost.Resize((int)width, (int)height);
}
}