Caliburn.Micro:使用 WPF 通过 IWindowManager 创建无边框窗口

发布于 2024-12-27 01:30:26 字数 277 浏览 4 评论 0 原文

使用 IWindowManager 。 codeplex.com" rel="nofollow">Caliburn.Micro,是否可以使用 ShowWindow 方法创建无边框窗口?

在这种情况下,窗口的内容是从用户控件生成的。 Caliburn.Micro 将创建一个窗口来托管 UserControl。

Using the IWindowManager of Caliburn.Micro, is it possible to create a borderless window using the ShowWindow method?

In this case, the content of the Window is generated from a UserControl. And Caliburn.Micro will create a Window to host the UserControl.

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

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

发布评论

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

评论(1

溺深海 2025-01-03 01:30:26

编辑:今天的状态:

在当前的 Caliburn.Micro v1.2(2011 年 7 月 20 日)版本中,无法在创建的窗口上设置属性。您可以继承 WindowManager 并重写 CreateWindow 方法:

public class BorderlessWindowManager : WindowManager
{
    protected override Window CreateWindow(object rootModel, bool isDialog, 
       object context)
    {
        var window = base.CreateWindow(rootModel, isDialog, context);
        window.WindowStyle = WindowStyle.None;
        window.ShowInTaskbar = false;
        window.AllowsTransparency = true;
        window.Background = new SolidColorBrush(Colors.Transparent);
        return window;
    }
}

新版本发布时:

是的,可以,使用 settings< /code> 参数:

public interface IWindowManager
{
    //...
    void ShowWindow(object rootModel, object context = null, 
         IDictionary<string, object> settings = null);
}

Caliburn.Micro 将使用此字典作为 [属性名称; property value] 包并通过反射将它们设置在创建的窗口上。
我从未创建过无边框窗口,但基于此 artice 像这样的东西应该有效:

windowManger.ShowWindow(viewModel, 
    settings: new Dictionary<string, object>
    {
        { "WindowStyle", WindowStyle.None},
        { "ShowInTaskbar", false},
        { "AllowsTransparency", true},
        { "Background", new SolidColorBrush(Colors.Transparent)},
    });

EDIT: The status today:

With the current Caliburn.Micro v1.2 (July 20, 2011) release it's not possible to set properties on the created window. You can inherit from the WindowManager and override the CreateWindow method:

public class BorderlessWindowManager : WindowManager
{
    protected override Window CreateWindow(object rootModel, bool isDialog, 
       object context)
    {
        var window = base.CreateWindow(rootModel, isDialog, context);
        window.WindowStyle = WindowStyle.None;
        window.ShowInTaskbar = false;
        window.AllowsTransparency = true;
        window.Background = new SolidColorBrush(Colors.Transparent);
        return window;
    }
}

When the new version released:

Yes it's possible, with the settings parameter:

public interface IWindowManager
{
    //...
    void ShowWindow(object rootModel, object context = null, 
         IDictionary<string, object> settings = null);
}

Caliburn.Micro will use this dictionary as [property name; property value] bag and set them on the created window with reflection.
I've never created a borderless window but based on this artice something like this should work:

windowManger.ShowWindow(viewModel, 
    settings: new Dictionary<string, object>
    {
        { "WindowStyle", WindowStyle.None},
        { "ShowInTaskbar", false},
        { "AllowsTransparency", true},
        { "Background", new SolidColorBrush(Colors.Transparent)},
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文