退出全屏时视频未调整为 window
Video no sizing to window when coming out of fullscreen
我正在使用 .NET 将媒体播放器作为 WPF 应用程序。
我刚刚做了全屏,效果很好。但是当我退出全屏时,如果我尝试调整 window 的大小,在 window 中播放的视频将不会延伸到 window。
我查了然后放了
<MediaElement Name="MediaPlayer" Grid.Row="1" LoadedBehavior="Manual" Stretch="Fill" />
Stretch="Fill"放了,我漏了什么?
这是我的全屏功能:
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
if (!fullscreen)
{
MediaPlayer.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
MediaPlayer.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
MediaPlayer.Stretch = System.Windows.Media.Stretch.Fill;
}
else
{
MediaPlayer.Width = 1280;
MediaPlayer.Height = 720;
this.WindowStyle = WindowStyle.SingleBorderWindow;
this.WindowState = WindowState.Normal;
MediaPlayer.Stretch = System.Windows.Media.Stretch.Fill;
}
fullscreen = !fullscreen;
}
}
edit:只有在进入全屏模式时才会遇到这个问题。我可以调整大小,并且视频将适合 window,前提是我之前没有将 window 全屏显示。
目前,您在全屏方法中对 MediaElement Width/Height 进行了硬编码,当您切换为全屏时,MediaElemet 会保持硬编码大小。删除它,它会很好地工作:
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
if (!fullscreen)
{
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
}
else
{
this.WindowStyle = WindowStyle.SingleBorderWindow;
this.WindowState = WindowState.Normal;
}
fullscreen = !fullscreen;
}
}
我正在使用 .NET 将媒体播放器作为 WPF 应用程序。
我刚刚做了全屏,效果很好。但是当我退出全屏时,如果我尝试调整 window 的大小,在 window 中播放的视频将不会延伸到 window。
我查了然后放了
<MediaElement Name="MediaPlayer" Grid.Row="1" LoadedBehavior="Manual" Stretch="Fill" />
Stretch="Fill"放了,我漏了什么?
这是我的全屏功能:
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
if (!fullscreen)
{
MediaPlayer.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
MediaPlayer.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
MediaPlayer.Stretch = System.Windows.Media.Stretch.Fill;
}
else
{
MediaPlayer.Width = 1280;
MediaPlayer.Height = 720;
this.WindowStyle = WindowStyle.SingleBorderWindow;
this.WindowState = WindowState.Normal;
MediaPlayer.Stretch = System.Windows.Media.Stretch.Fill;
}
fullscreen = !fullscreen;
}
}
edit:只有在进入全屏模式时才会遇到这个问题。我可以调整大小,并且视频将适合 window,前提是我之前没有将 window 全屏显示。
目前,您在全屏方法中对 MediaElement Width/Height 进行了硬编码,当您切换为全屏时,MediaElemet 会保持硬编码大小。删除它,它会很好地工作:
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2)
{
if (!fullscreen)
{
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
}
else
{
this.WindowStyle = WindowStyle.SingleBorderWindow;
this.WindowState = WindowState.Normal;
}
fullscreen = !fullscreen;
}
}