使用Xamarin Forms Mac OS记住窗口位置 [英] Remember window position with Xamarin Forms Mac OS

查看:92
本文介绍了使用Xamarin Forms Mac OS记住窗口位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道XCode支持自动保存以记住窗口位置.我看到它是免费的.

I understand that XCode supports AutoSave for remembering window position. I see it free documented.

当平台为macOS时,Xamarin Forms 5怎么样?

What about Xamarin Forms 5, when the platform is macOS?

这是我的一些代码,如果有帮助的话:

This is some of my code, if it helps:

public class AppDelegate : FormsApplicationDelegate
{
    NSWindow window;
    public AppDelegate()
    {
        var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;

        var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768);
        window = new NSWindow(rect, style, NSBackingStore.Buffered, false)
        {
            Title = "Elderly and Infirm Rota",
            TitleVisibility = NSWindowTitleVisibility.Visible
        };

        InstallApplicationFiles();
    }


#Update


#Update

我也提到限制窗口大小的评论.我现在已经计算出该位( NSWindow.MinSize ):

It the comments I also referred to limiting the size of the window. I have now worked out that bit (NSWindow.MinSize):

    NSWindow window;
    public AppDelegate()
    {
        var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;

        var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768);
        window = new NSWindow(rect, style, NSBackingStore.Buffered, false)
        {
            Title = "Elderly and Infirm Rota",
            TitleVisibility = NSWindowTitleVisibility.Visible,
            MinSize = rect.Size
        };

        InstallApplicationFiles();
    }

现在我必须解决窗口的大小/位置并记住它.

Now I have to address the window size / position and remembering it.

推荐答案

事实证明这并不难.Visual Studio for Mac缺少针对Xcode描述的某些设置(我认为).请参阅: frameAutoSaveName

Turns out it was not too hard. Visual Studio for Mac is missing some settings (I think) that are described for Xcode. See: frameAutoSaveName

此处提供的答案也很有用.对我来说,部分问题是要使用正确的术语来寻找答案,在这种情况下, NSWindow 很重要.

The answers provided here were also useful. Part of the problem for me was having the right terms for search for an answer and in this case NSWindow was important.

在我的macOS AppDeletegate 构造函数中,我现在执行此操作:

In my macOS AppDeletegate constructor I now do this:

public AppDelegate()
{
    var style = NSWindowStyle.Closable | NSWindowStyle.Resizable | NSWindowStyle.Titled;

    var rect = new CoreGraphics.CGRect(200, 1000, 1024, 768);
    window = new NSWindow(rect, style, NSBackingStore.Buffered, false)
    {
        Title = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleDisplayName").ToString(),
        TitleVisibility = NSWindowTitleVisibility.Visible,
        MinSize = rect.Size,
        FrameAutosaveName = "xxxxx"
    };

    InstallApplicationFiles();
}

请注意 FrameAutosaveName 属性的其他设置:

Notice the additional setting of the FrameAutosaveName property:

FrameAutosaveName = "xxxxx"

现在,当我关闭应用程序时,窗口位置会被记住.

Now the window position is remembers when I close the application.

请告诉我是否有一种方法可以在Visual Studio for Mac GUI中直接进行设置.

Please let me know if there was a way to set this directly in Visual Studio for Mac GUI.

这篇关于使用Xamarin Forms Mac OS记住窗口位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆