1

                                           媒体元素

MediaElementPopUp. 当我将 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;
        }
    }
4

2 回答 2

3

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

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;
    }
}
于 2014-03-06T14:54:52.357 回答
2

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

请参阅此线程:无法创建全屏 WPF 弹出窗口

于 2013-08-21T14:01:24.120 回答