我可以从 VisualTree 中删除 ChildWindow 并将其放回以实现全屏吗?
我有一个弹出窗口,它是一个子窗口。在该弹出窗口中,我有一个 UserControl (MediaPreviewView),其中有一个 MediaElement 和一些用于控制视频的按钮。我的要求是,我需要一个全屏按钮,并在用户单击该按钮时全屏显示视频。
我正在使用 MVVM,因此我决定在 MVVM Light 中尝试使用消息传递。我正在向我的基本视图发送一条消息。在该视图的代码隐藏中,我显示了一个网格(隐藏在 XAML 的底部,具有较高的 zindex)。我的消息包含 MediaPreviewControl 并且我正在将 Grid.Children.Add( 设置为控件。我已经尝试了多种方法,并且可以使 ChildWindow 不可见,但按钮不起作用。似乎 ChildWindow即使宽度和高度为 0,仍然位于按钮顶部。 是否有更好可行的方法让我的 MediaPreviewView 全屏显示?
public class MediaPreviewFullScreenMessage
{
public MediaPreviewView PreviewView { get; set; }
public ChildWindow ContainerChildWindow { get; set; }
public bool ChangeToFullScreen { get; set; }
}
// Register for FullScreen media preview
Messenger.Default.Register<MediaPreviewFullScreenMessage>(this,
(fullScreenMessage) =>
{
this.fullScreenHolderGrid.Visibility = fullScreenMessage.ChangeToFullScreen ? Visibility.Visible : Visibility.Collapsed;
this.fullScreenHolderGrid.Children.Clear();
if (fullScreenMessage.ChangeToFullScreen)
{
// I've tried, Visibility, width and height = 0 on the fullScreenMessage.ContainerChildWindow, even a TranslateTransform
....
}
});
I have a popup that is a ChildWindow. Inside that popup I have a UserControl (MediaPreviewView) that has a MediaElement and some buttons to control the video. My requirements state that I need a fullscreen button and show the video fullscreen when the user clicks on the button.
I'm using MVVM, so I decided to try this with Messaging in the MVVM Light. I'm sending a message to my base View. Inside that View's codebehind, I'm showing a Grid (hidden and at the bottom of the XAML, with a high zindex). My message contains the MediaPreviewControl and I'm setting the Grid.Children.Add( to the control. I've tried multiple things, and can get the ChildWindow to be invisible, but the buttons don't work. It seems that the ChildWindow is still on top of the buttons, even though the width and height was 0.
Is there a better a workable approach to making my MediaPreviewView fullscreen?
public class MediaPreviewFullScreenMessage
{
public MediaPreviewView PreviewView { get; set; }
public ChildWindow ContainerChildWindow { get; set; }
public bool ChangeToFullScreen { get; set; }
}
// Register for FullScreen media preview
Messenger.Default.Register<MediaPreviewFullScreenMessage>(this,
(fullScreenMessage) =>
{
this.fullScreenHolderGrid.Visibility = fullScreenMessage.ChangeToFullScreen ? Visibility.Visible : Visibility.Collapsed;
this.fullScreenHolderGrid.Children.Clear();
if (fullScreenMessage.ChangeToFullScreen)
{
// I've tried, Visibility, width and height = 0 on the fullScreenMessage.ContainerChildWindow, even a TranslateTransform
....
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单地最大化
ChildWindow
怎么样?在您的全屏Button
后面,UPDATE
在
ChildWindow
的默认样式中,它的Grid
称为ContentRoot
通过RenderTransform
设置ChildWindow
的位置。这就是为什么您需要重置TranslateX
和TranslateY
以使其位于左上角。How about just simply maximising the
ChildWindow
? Behind your full screenButton
you do,UPDATE
In the
ChildWindow
's default style, it has thisGrid
calledContentRoot
which sets the position of theChildWindow
byRenderTransform
. That's why you need to reset theTranslateX
andTranslateY
to make it top left.