如何从 Caliburn Windows 管理器对话框中删除最大化按钮

发布于 2024-12-13 10:43:41 字数 2048 浏览 0 评论 0原文

我正在使用 Caliburn Micro Window Manager 来显示一个对话框。我想从对话框中删除最大化和最小化按钮。

如果我查看 Windows Manager 源代码(在 WPF 下),我可以看到第三个参数,它允许我将设置传递到对话框。我的问题是我无法传递第三个参数 - 我收到错误。这可以在 hello 窗口管理器示例项目中复制。

有什么想法吗?

不知何故,我似乎引用了一个 IWindowManager,它只允许 ShowDialog 有 2 个参数。

这就是我想要做的,但会导致错误:

var loginViewModel = new LoginViewModel();

WindowManager windowManager = new WindowManager();

Dictionary<string, object> settings = new Dictionary<string, object>();

// add settings here to pass to dialog

windowManager.ShowDialog(loginViewModel, null, settings);

这是 IWindowManager 界面,显示 3 个参数:

public interface IWindowManager
{
    /// <summary>
    /// Shows a modal dialog for the specified model.
    /// </summary>
    /// <param name="rootModel">The root model.</param>
    /// <param name="context">The context.</param>
    /// <param name="settings">The optional dialog settings.</param>
    /// <returns>The dialog result.</returns>
    bool? ShowDialog(object rootModel, object context = null, IDictionary<string, object> settings = null);

    /// <summary>
    /// Shows a non-modal window for the specified model.
    /// </summary>
    /// <param name="rootModel">The root model.</param>
    /// <param name="context">The context.</param>
    /// <param name="settings">The optional window settings.</param>
    void ShowWindow(object rootModel, object context = null, IDictionary<string, object> settings = null);

    /// <summary>
    /// Shows a popup at the current mouse position.
    /// </summary>
    /// <param name="rootModel">The root model.</param>
    /// <param name="context">The view context.</param>
    /// <param name="settings">The optional popup settings.</param>
    void ShowPopup(object rootModel, object context = null, IDictionary<string, object> settings = null);
}

I am using the Caliburn Micro Window Manager to display a dialog. I would like to remove the maximize and minimize buttons from the dialog.

If I look at the Windows Manager source (under WPF) I can see a third parameter that lets me pass settings to the dialog. My problem is that I can't pass a third parameter - I get an error. This can be replicated in the hello window manager example project.

Any ideas?

Somehow I seem to be referencing an IWindowManager that only allows 2 parameters to ShowDialog.

This is what I want to do but causes an error:

var loginViewModel = new LoginViewModel();

WindowManager windowManager = new WindowManager();

Dictionary<string, object> settings = new Dictionary<string, object>();

// add settings here to pass to dialog

windowManager.ShowDialog(loginViewModel, null, settings);

This is IWindowManager interface that shows 3 parameters:

public interface IWindowManager
{
    /// <summary>
    /// Shows a modal dialog for the specified model.
    /// </summary>
    /// <param name="rootModel">The root model.</param>
    /// <param name="context">The context.</param>
    /// <param name="settings">The optional dialog settings.</param>
    /// <returns>The dialog result.</returns>
    bool? ShowDialog(object rootModel, object context = null, IDictionary<string, object> settings = null);

    /// <summary>
    /// Shows a non-modal window for the specified model.
    /// </summary>
    /// <param name="rootModel">The root model.</param>
    /// <param name="context">The context.</param>
    /// <param name="settings">The optional window settings.</param>
    void ShowWindow(object rootModel, object context = null, IDictionary<string, object> settings = null);

    /// <summary>
    /// Shows a popup at the current mouse position.
    /// </summary>
    /// <param name="rootModel">The root model.</param>
    /// <param name="context">The view context.</param>
    /// <param name="settings">The optional popup settings.</param>
    void ShowPopup(object rootModel, object context = null, IDictionary<string, object> settings = null);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

大海や 2024-12-20 10:43:41
dynamic settings = new ExpandoObject();
            settings.WindowStyle = WindowStyle.ToolWindow;
            settings.ShowInTaskbar = false;
            settings.Title = "Test";

windowManager.ShowDialog(loginViewModel, "Modeless", settings);
dynamic settings = new ExpandoObject();
            settings.WindowStyle = WindowStyle.ToolWindow;
            settings.ShowInTaskbar = false;
            settings.Title = "Test";

windowManager.ShowDialog(loginViewModel, "Modeless", settings);
套路撩心 2024-12-20 10:43:41

我不记得最近版本的 Caliburn.Micro 使用带有三个参数的 IWindowManager.ShowDialog。您是否可能引用了Codeplex 网站上的此链接?这似乎是 Rob 拒绝的用户请求。

您可能知道,ShowDialog() 将导致 IWindowManager 实例化它找到的视图(通过命名约定)并将其附加到您提供的任何视图模型(例如 LoginViewModel 附加到名为 LoginView 的“找到的”视图)。

我猜 LoginView 对您来说是一个 UserControl,但您可以将此视图设置为常规窗口,然后设置 WindowStyle 属性(在 XAML 中)以使用没有最大化按钮的选项之一。 这篇 MSDN 文章显示了各种枚举选项。 WindowStyle.ToolWindow 是唯一包含关闭按钮而不包含最小/最大按钮的窗口,但由于它更改了关闭按钮的外观,因此您可能更喜欢 WindowStyle.None 并且只定义自己的窗口镶边和按钮。

<Window x:Class="MyNamespace.LoginView"
        ...
        WindowStyle="ToolWindow">
    ...
</Window>

I don't recall any recent version of Caliburn.Micro that used IWindowManager.ShowDialog with three parameters. Are you maybe referring to this link from the Codeplex site? It appears to be a user request that Rob rejected.

As you probably know, ShowDialog() will cause the IWindowManager to instantiate a view it finds (by naming convention) and attach it to whatever viewmodel you provide it (e.g. LoginViewModel is attached to a "found" view called LoginView).

I'm guessing that LoginView is a UserControl for you, but you can have this view be a regular Window and then set the WindowStyle property (in XAML) to use one of the options that does not have the maximize button. This MSDN article shows the various enumeration options. WindowStyle.ToolWindow is the only one that includes the close button and not the min/max buttons, but because it changes the appearance of the close button, you may prefer WindowStyle.None and just define your own window chrome and buttons.

<Window x:Class="MyNamespace.LoginView"
        ...
        WindowStyle="ToolWindow">
    ...
</Window>
海拔太高太耀眼 2024-12-20 10:43:41

而不是将视图作为用户控件使其成为窗口并设置其ResizeMode="NoResize"

<Window x:Class="Company.Project.Views.MyView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    ResizeMode="NoResize">

现在,您将只有红色“X”关闭按钮,而没有最大化/最小化按钮, 。

Instead of having your View as Usercontrol make it a Window and set its ResizeMode="NoResize"

<Window x:Class="Company.Project.Views.MyView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    ResizeMode="NoResize">

Now you will only have red "X" close button and no maximize/minimize buttons.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文