[英]Xamarin.Forms SystemFontOfSize missing some overloads
According to Xamarin.Forms documentation , I should be able to set font attributes using Font.SystemFontOfSize([size], [FontAttributes])
method. 根据Xamarin.Forms 文档 ,我应该能够使用Font.SystemFontOfSize([size], [FontAttributes])
方法设置字体属性。 But when I create a new Blank App (Xamarin.Forms Portable) project and add the following code to App.cs in the portable project, for some reason I don't have access to all of the overloads for Font.SystemFontOfSize(...)
and no access to Xamarin.Forms.FontAttributes
enum. 但是,当我创建一个新的Blank App(Xamarin.Forms可移植)项目并将以下代码添加到可移植项目中的App.cs时,由于某种原因,我无法访问Font.SystemFontOfSize(...)
所有重载Font.SystemFontOfSize(...)
并且无法访问Xamarin.Forms.FontAttributes
枚举。
// FontExample/App.cs
using System;
using Xamarin.Forms;
namespace FontExample {
public class App {
public static Page GetMainPage() {
return new ContentPage {
Content = new Label {
Text = "Hello, Forms !",
Font = Font.SystemFontOfSize(14, FontAttributes.Italic)
},
};
}
}
}
There seem to be only two overloads of SystemFontOfSize and the compiler gives me: SystemFontOfSize似乎只有两个重载,编译器给了我:
The name 'FontAttributes' does not exist in the current context [...] 名称'FontAttributes'在当前上下文中不存在[...]
The project seem to have all the default references in place (.NET, Xamarin.Forms.Core, Xamarin.Forms.Xaml), I did not touch them. 该项目似乎具有所有默认引用(.NET,Xamarin.Forms.Core,Xamarin.Forms.Xaml),我没有碰过它们。
But, if I download a sample project with exactly the same setup (calling Font.SystemFontOfSize
from within the portable project with the same references), the project compiles fine and I seem to have access to all of the Font.SystemFontOfSize
overloads as well as the Xamarin.Forms.FontAttributes
enum. 但是,如果我下载具有完全相同设置的示例项目 (从具有相同引用的便携式项目中调用Font.SystemFontOfSize
),则该项目可以正常编译,并且我似乎可以访问所有Font.SystemFontOfSize
重载以及Xamarin.Forms.FontAttributes
枚举。
Why don't I have access to all Xamarin.Forms API features when creating a new project myself? 为什么我自己创建一个新项目时无法访问所有Xamarin.Forms API功能? I can't find any significant difference between the newly created Blank App (Xamarin.Forms Portable) and the sample project linked above. 我找不到新创建的Blank App(Xamarin.Forms Portable)和上面链接的示例项目之间的任何显着差异。
It sounds like your build is getting confused somewhere. 听起来您的构建在某处变得困惑。
Try removing the Xamarin.Forms references via NuGet ; 尝试通过NuGet删除Xamarin.Forms引用; close-down the project and re-open; 关闭项目并重新打开; re-add Xamarin.Forms via NuGet . 通过NuGet重新添加Xamarin.Forms 。 The current latest version should be like v1.2.3x. 当前的最新版本应类似于v1.2.3x。
If the above approach doesn't work, try doing a clean build (In Visual Studio, Build -> Clean Solution') and then try to rebuild. 如果上述方法不起作用,请尝试执行干净的生成(在Visual Studio中,“生成”->“干净的解决方案”),然后尝试重新生成。
As a final resort go into each application folder and delete the 'obj' and 'bin' directories and rebuild. 最后,进入每个应用程序文件夹,然后删除“ obj”和“ bin”目录,然后进行重建。
One of the above should resolve your issue. 以上之一可以解决您的问题。
Note - however that there is an issue with using Font.SystemFontOfSize({fontsize}, {font-attributes-enum})
, in a previous version of Xamarin.Forms that would cause this overload to crash the application with an exception . 注-但是,有使用问题Font.SystemFontOfSize({fontsize}, {font-attributes-enum})
在Xamarin.Forms的早期版本,将导致此过载与异常应用程序崩溃 。
Unless they have now corrected this you will need to use something like Font.SystemFontOfSize(30).WithAttributes(FontAttributes.Bold)
instead to get around this. 除非他们现在已纠正此问题,否则您将需要使用诸如Font.SystemFontOfSize(30).WithAttributes(FontAttributes.Bold)
来解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.