none
WPF关于MediaElement全屏显示的问题 RRS feed

答案

  • 你是想问MediaElement如何进行全屏显示么?

    如果是这样,那么你听说的是正确的,DockPanel的确可以完成,至于如何完成,参考下面的代码:

    Xaml

    <Window x:Class="MediaElementFullScreen.MainWindow"

            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

            Title="MainWindow" Height="350" Width="525">

        <DockPanel Margin="40" Name="layoutRoot">

            <MediaElement x:Name="mediaControl"/>

        </DockPanel>

    </Window>

    Code-Behind

    public partial class MainWindow : Window

        {

            private bool fullScreen = false;

            public MainWindow()

            {

                InitializeComponent();

                mediaControl.MouseDown += delegate

                {

                    if (!fullScreen)

                    {

                        layoutRoot.Children.Remove(mediaControl);

                        this.Content = mediaControl;

                        this.WindowStyle = WindowStyle.None;

                        this.WindowState = WindowState.Maximized;

     

                    }

                    else

                    {

                        this.Content = layoutRoot;

                        layoutRoot.Children.Add(mediaControl);

                        this.WindowStyle = WindowStyle.SingleBorderWindow;

                        this.WindowState = WindowState.Normal;

                    }

     

                    fullScreen = !fullScreen;

                };

            }

        }

    看完代码估计你就懂了。

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年2月23日 13:56
    版主

全部回复

  • 你是想问MediaElement如何进行全屏显示么?

    如果是这样,那么你听说的是正确的,DockPanel的确可以完成,至于如何完成,参考下面的代码:

    Xaml

    <Window x:Class="MediaElementFullScreen.MainWindow"

            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

            Title="MainWindow" Height="350" Width="525">

        <DockPanel Margin="40" Name="layoutRoot">

            <MediaElement x:Name="mediaControl"/>

        </DockPanel>

    </Window>

    Code-Behind

    public partial class MainWindow : Window

        {

            private bool fullScreen = false;

            public MainWindow()

            {

                InitializeComponent();

                mediaControl.MouseDown += delegate

                {

                    if (!fullScreen)

                    {

                        layoutRoot.Children.Remove(mediaControl);

                        this.Content = mediaControl;

                        this.WindowStyle = WindowStyle.None;

                        this.WindowState = WindowState.Maximized;

     

                    }

                    else

                    {

                        this.Content = layoutRoot;

                        layoutRoot.Children.Add(mediaControl);

                        this.WindowStyle = WindowStyle.SingleBorderWindow;

                        this.WindowState = WindowState.Normal;

                    }

     

                    fullScreen = !fullScreen;

                };

            }

        }

    看完代码估计你就懂了。

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年2月23日 13:56
    版主
  • 你好 yimi55555,

    因为我们没有收到关于你这个帖子解决状态的信息,而且,回复中已经包含了解决方案,因此我将标记你的帖子为“已解决”。

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年2月28日 15:45
    版主
  • 如果有其他的控件呢,你的方法就貌似不管用了的。

    • 已编辑 GodwinQ 2015年1月21日 4:13
    2015年1月21日 4:13