gpt4 book ai didi

c# - 设备类在 .net MAUI 中被标记为过时

转载 作者:行者123 更新时间:2023-12-05 05:35:41 24 4
gpt4 key购买 nike

最近我更新到最新版本的 .net MAUI,我有点惊讶地看到 MAUI Device 类现在已被标记为 Obsolete

我有多个用例,在这些用例中我将设备类用于某物或其他。

例如现在mainthread方法已经过时了:

Device.BeginInvokeOnMainThread(() =>{});

现在是否有一个新的助手类将执行这些事件,或者我是否遗漏了什么?

enter image description here

最佳答案

更新:

Maui 现在有一个命名空间,其中包含一堆与设备相关的类,您可以在 Microsoft.Maui.Devices 下找到它们

enter image description here

OG 回答:

正如 Jason 在评论中指出的那样,显然他们已经决定解散整个 Device 类,现在那里存在的所有功能要么被移出,要么被其他选项替换,尽管更多信息不在同一树下 here

Device

This is the containing class, and everything it had is now obsolete. Ready for removal in .NET 7!GetNamedSize, NamedSize and IFontNamedSizeServiceThis used to be the only way to get scaled font sizes, but now it is built into Font. If we want to actually expose those values to the user, we can maybe use a "stringly-typed enum" to allow for supporting the other values on the system. We only had Title1, but there is also a Title2 and Title3.Device.Styles and ISystemResourcesProvider ("Device Styles" eg: {DynamicResource TitleStyle})This is the way to get the OS font styles. This may be more popular than I think, but I am just pre-emptively removing it for now.In both cases (named sizes and device styles), I may be missing the real uses here, so this PR is to show what is going and can start a conversation.

If anything, some things need to be tweaked and not exist only in the Device class.

Named SizesNOTE: these values appear to be magical and do things, but at XAML parse time, they are translated into a double with no idea that they were special values. Thus, they never did respond to OS changes. Once set, they are just a number and nothing special

对于命名大小,我们可以让 Font 更智能,并且实际上将字符串类型的值作为一个字段。例如:

class Font {
double Size;
string NamedSize;
string Family;
}

Then the font manager can do a check like this:

double realSize;
if (font.NamedSize != null) {
realSize = GetSizeFromName(font.NamedSize);
} else {
realSize = font.Size * scalingFactor;
}

希望这对某人有所帮助:)

关于c# - 设备类在 .net MAUI 中被标记为过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73451100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com