- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如何为 Mahapps MetroWindow 添加从全屏模式到窗口模式的动态切换功能,反之亦然?
从普通窗口开始
切换到全屏后,右上角的窗口按钮(最小化/最大化/关闭)仍然可见(但它们不应该像标题栏一样可见)。标题栏的预留空间似乎还在。
相反,最初是从全屏状态(没有按钮,除了中间的 Hello 按钮和没有标题栏 => 正如预期的那样)
...但是当切换回正常窗口状态时,标题又回来了,但左上角的按钮不见了。
我在代码中做错了什么吗?我使用了派生的行为。切换时执行的有趣部分是:
private static void OnIsFullscreenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var window = (MetroWindow)sender;
var oldValue = (bool)e.OldValue;
var newValue = (bool)e.NewValue;
if (newValue == oldValue || window == null)
{
return;
}
if (newValue)
{
window.Tag = window.WindowState;
window.Topmost = true;
window.UseNoneWindowStyle = true;
window.IgnoreTaskbarOnMaximize = true;
window.ShowTitleBar = false;
window.WindowStyle = WindowStyle.None;
window.WindowState = WindowState.Maximized;
}
else
{
window.Topmost = false;
window.UseNoneWindowStyle = false;
window.IgnoreTaskbarOnMaximize = false;
window.ShowTitleBar = true;
window.WindowStyle = WindowStyle.SingleBorderWindow;
window.WindowState = (WindowState)window.Tag;
}
}
将模拟行为附加到默认 Window WPF 控件,一切都按预期工作。
我以这种方式附加行为:
<controls:MetroWindow ... local:FullscreenBehavior.IsFullscreen="{Binding Fullscreen}">
<!-- code above sets initial state depending on ViewModel value -->
<!-- code below fires mode switching when a defined key is pressed => executes OnIsFullscreenChanged method -->
<i:Interaction.Behaviors>
<behaviours:BorderlessWindowBehavior />
<behaviours:WindowsSettingBehaviour />
<behaviours:GlowWindowBehavior />
<modern:FullscreenBehavior FullscreenKey="{Binding FullscreenKey}" />
</i:Interaction.Behaviors>
...
编辑:明确设置窗口按钮的状态当我扩展方法以明确地将状态设置为正确的值时,似乎出现了另一个奇怪的效果:
private static void OnIsFullscreenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
var window = (MetroWindow)sender;
var oldValue = (bool)e.OldValue;
var newValue = (bool)e.NewValue;
if (newValue == oldValue || window == null)
{
return;
}
if (newValue)
{
window.Tag = window.WindowState;
window.Topmost = true;
window.UseNoneWindowStyle = true;
window.IgnoreTaskbarOnMaximize = true;
window.ShowTitleBar = false;
window.ShowCloseButton = false;
window.ShowMaxRestoreButton = false;
window.ShowMinButton = false;
window.WindowStyle = WindowStyle.None;
window.WindowState = WindowState.Maximized;
}
else
{
window.Topmost = false;
window.UseNoneWindowStyle = false;
window.IgnoreTaskbarOnMaximize = false;
window.ShowTitleBar = true;
window.ShowCloseButton = true;
window.ShowMaxRestoreButton = true;
window.ShowMinButton = true;
window.ShowCloseButton = true;
window.ShowMaxRestoreButton = true;
window.WindowStyle = WindowStyle.SingleBorderWindow;
window.WindowState = (WindowState)window.Tag;
}
}
窗口“有时”在边界处被切割,有时看起来是正确的(如顶部的第一张图片)。我也不知道(还)标题栏的空间是否在最初以全屏启动时不再保留(似乎有区别,不知道为什么)。
最佳答案
当前的 1.0 版本中有一个小错误。如果您切换 UseNoneWindowStyle
,它不会恢复按钮和工具栏。我会尽快解决这个问题。
因此,这里有一些适合您的解决方法。
public static readonly DependencyProperty ToggleFullScreenProperty =
DependencyProperty.Register("ToggleFullScreen",
typeof(bool),
typeof(MainWindow),
new PropertyMetadata(default(bool), ToggleFullScreenPropertyChangedCallback));
private static void ToggleFullScreenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
var metroWindow = (MetroWindow)dependencyObject;
if (e.OldValue != e.NewValue)
{
var fullScreen = (bool)e.NewValue;
if (fullScreen)
{
metroWindow.UseNoneWindowStyle = true;
metroWindow.IgnoreTaskbarOnMaximize = true;
metroWindow.ShowMinButton = false;
metroWindow.ShowMaxRestoreButton = false;
metroWindow.ShowCloseButton = false;
metroWindow.WindowState = WindowState.Maximized;
}
else
{
metroWindow.UseNoneWindowStyle = false;
metroWindow.ShowTitleBar = true; // <-- this must be set to true
metroWindow.IgnoreTaskbarOnMaximize = false;
metroWindow.ShowMinButton = true;
metroWindow.ShowMaxRestoreButton = true;
metroWindow.ShowCloseButton = true;
metroWindow.WindowState = WindowState.Normal;
}
}
}
public bool ToggleFullScreen
{
get { return (bool)GetValue(ToggleFullScreenProperty); }
set { SetValue(ToggleFullScreenProperty, value); }
}
希望这对您有所帮助。
关于c# - Mahapps 的全屏行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28022262/
我在 WPF(C#) 中定义了一个带有绑定(bind)项源的 SplitButton。 只有当用户单击 SplitButton 右侧的箭头时,项目列表才会展开。 当用户点击SplitButton区域时
任何人都可以建议我如何在 MahApps Metro 布局中实现图 block 的拖放。谢谢.. 最佳答案 我们使用 punker76 的另一个库取得了成功。 它轻量级且易于实现! GitHub ht
我正在开发一个 Office 加载项,并想添加一个 WPF Mahapps Windows。 一切顺利,但我无法应用 Mahapps Windows 样式。 看教程here我看到我更新了 App.xa
我正在开发一个 Office 加载项,并想添加一个 WPF Mahapps Windows。 一切顺利,但我无法应用 Mahapps Windows 样式。 看教程here我看到我更新了 App.xa
我有一个使用默认颜色加载的 MetroWindow。我有一个选项供用户更改样式。在窗口中,我使用内容控件在初始化此窗口时从代码隐藏动态设置用户控件(此窗口是从另一个应用程序初始化的,因此没有 app.
我使用的是 MahApps.Metro 版本 1.2.0.0。我已将主题设置为深色主题。这在我运行应用程序时工作正常,但仍然在我的设计器中显示浅色主题。 关于导致此问题的原因的想法? 最佳答案 我在
这是我的按钮: 和 content使用此 Style 时总是使用小写字母 最佳答案 你应该使用 Controls:ButtonHelper.PreserveTextCase="True" 以防止小写
我开始介绍 MahApps .Metro(真的很棒)在我的 WPF 应用程序中,我最喜欢的按钮是默认的。问题是它把我所有的文本都大写,我不想要它。 最佳答案 您可以通过为 Window.Resourc
我想将 MahApps 库中的图标放入普通按钮中。我是这样试的: 结局是这样的: 那么如何将这个图标整合到这个按钮的合适位置呢? 最佳答案 您有 2 个选择。 首先,您可以使用图标资源(带有 Met
我正在使用Mahapps,但无法为窗口标题和组框标题等设置适当的大小写。 我尝试了谷歌搜索和版式设置。 如果有人知道你可以在这里帮我。 谢谢 最佳答案 新版本: 窗口标题 组框 设置样式(选项1)或
目前我正在使用 这就是结果: 我还发现了这种支持的颜色:https://github.com/MahApps/MahApps.Metro/tree/master/MahApps.Metro/Style
我正在尝试设置 SimpleChildWindow来自 MahApps 包 不幸的是,我无法理解示例并有几个问题: 它说: Directly in XAML 我应该把它放在哪里? 在父窗口中还是在单独
我正在使用 MahApps在 WPF 项目上,我正在尝试使用 MahApps 的内置样式对 DataGrid 控件提供一些验证, 但我定义的验证样式没有显示。 DataGrid 是:
如何为 Mahapps MetroWindow 添加从全屏模式到窗口模式的动态切换功能,反之亦然? 从普通窗口开始 切换到全屏后,右上角的窗口按钮(最小化/最大化/关闭)仍然可见(但它们不应该像标题栏
首先,非常感谢 MahApps。多么酷的项目! 我有一个用 WPF 编写的应用程序,我已经应用了 MahApps 库。我使用了本教程: http://mahapps.com/guides/quick-
我正在使用 MahApps Metro 窗口样式,并且我想在用户单击窗口的关闭按钮时捕获事件。 我已将 ShutdownMode 设置为 OnExplicitShutdown,所以我需要调用 Appl
有没有办法在 mahapps 地铁中根据每个控件更改主题(亮/暗)? 我的问题是,我有一个使用 Light 主题的窗口,但我有一部分的背景非常暗,我无法让 ComboBox 正确显示,即使我更改了背景
我正在尝试使用 MahApps.Metro 0.13.1.0 在窗口标题栏中添加一个“刷新”按钮。 我的 App.xaml 是这样的:
我有 ComboBox和每个索引我想改变这个 Watermark因此。 是否可以更改此 Property通过背后的代码? 最佳答案 如 mytextBox不在模板内或不同的名称范围内,您可以在代码中
有没有办法改变 MetroWindow 中的按钮前景? 我什至试图覆盖 IronicallyNamedChromelessButtonStyle 但前景色仍然相同。 编辑: 按钮位于窗口栏中(例如关闭
我是一名优秀的程序员,十分优秀!