WPF:为什么PopUp中的MediaElement不能调整屏幕高度?

时间:2013-04-25 06:20:21

标签: wpf fullscreen mediaelement

MediaElement

我在MediaElement内有PopUp控件。当我将MediaElement调整为宽屏幕时,会在底部剪切一个区域(参见图像)。

我做错了什么?怎么解决?非常感谢你!

XAML:

    <Popup PlacementRectangle="-500,0,0,0" Placement="Relative" IsOpen="True" Name="popup">
        <MediaElement Name="me" Width="480" Height="360" Volume="1"
            MouseLeftButtonUp="me_MouseLeftButtonUp"/>
    </Popup>

代码:

    bool fullscreen = false;
    private void me_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        fullscreen = !fullscreen;
        if (fullscreen)
        {
            popup.PlacementRectangle = new Rect(0, 0, 0, 0);
            popup.Placement = PlacementMode.Absolute;
            me.Width = Screen.PrimaryScreen.Bounds.Width;
            me.Height = Screen.PrimaryScreen.Bounds.Height;
        }
        else
        {
            popup.PlacementRectangle = new Rect(-500, 0, 0, 0);
            popup.Placement = PlacementMode.Relative;
            me.Width = 480;
            me.Height = 360;
        }
    }

2 个答案:

答案 0 :(得分:2)

弹出窗口不能覆盖超过75%的屏幕。

请参阅此主题:Can't create a fullscreen WPF popup

答案 1 :(得分:2)

我找到了解决此问题的方法。 只需从Popup的子项开始搜索可视树,直到找到PopupRoot类型的父类。您可以将其宽度和高度设置为您喜欢的任何值。 这对我有用:

for (var parent = Child as FrameworkElement; parent != null; parent = VisualTreeHelper.GetParent(parent) as FrameworkElement)
{
    if (parent.GetType().Name == "PopupRoot")
    {
        parent.Width = Target.ActualWidth;
        parent.Height = Target.ActualHeight;
        break;
    }
}