WPF 在 mediaElement 上双击进入全屏并不总是有反应
我一直在寻找一种简单的方法来使我的窗口(仅包含 mediaElement)在双击时全屏显示。由于我是 WPF/C# 新手,所以我按照建议的方式进行了操作
这是事件处理程序:
private void mediaElement1_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2 && fullscreen==false)
{
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
}
else if (e.ClickCount == 2 && fullscreen == true)
{
this.WindowStyle = WindowStyle.SingleBorderWindow;
this.WindowState = WindowState.Normal;
}
fullscreen = !fullscreen;
}
I've been searching the easy way to make my window (which contains only a mediaElement) go full screen when it's double clicked. Since I'm new to WPF/C# I did it the way it was suggested here. It works, but it doesn't react always and sometimes I even have to click more than 3 times in row to get it into full screen or restored.
Here is the event handler:
private void mediaElement1_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 2 && fullscreen==false)
{
this.WindowStyle = WindowStyle.None;
this.WindowState = WindowState.Maximized;
}
else if (e.ClickCount == 2 && fullscreen == true)
{
this.WindowStyle = WindowStyle.SingleBorderWindow;
this.WindowState = WindowState.Normal;
}
fullscreen = !fullscreen;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下代码演示了如何通过双击媒体元素使窗口全屏显示。只需将“path_to_file”更改为 DemoWindow.xaml.cs 中文件的适当路径即可
。 导入:必须设置 MediaElement 的 Source 属性以启用 MouseLeftButtonUp 事件。否则不会调用事件处理程序。
DemoWindow.xaml
DemoWindow.xaml.cs
参考
https://diptimayapatra.wordpress.com/2010/03/04/full-screen-view-for-media-element-in-wpf/
The following code demonstrate how to make the window fullscreen by double clicking in the media element. Just change "path_to_file" for the appropriated path the file in the DemoWindow.xaml.cs
Importart: The Source property from MediaElement must be set to enable the MouseLeftButtonUp event. Otherwise the event handler is not called.
DemoWindow.xaml
DemoWindow.xaml.cs
Reference
https://diptimayapatra.wordpress.com/2010/03/04/full-screen-view-for-media-element-in-wpf/
使用这个:
这是最简单的方法!
Use this:
Its the easiest way !