【发布时间】:2020-10-19 22:10:16
【问题描述】:
我对 xlmns 和 x:Static 绑定有疑问。
我的“Test.Constants”静态类定义
namespace Test
{
static class Constants
{
static public int TXT_SIZE=46;
static public Color TXT_COLOR=Color.Red;
}
}
我的 XAML:
(snip)
xmlns:ctes="clr-namespace:Test;assembly=Test"
(snip)
<Label x:Name="lblTest" FontSize="{x:Static ctes:Constants.TXT_SIZE}" TextColor="{x:Static ctes:Constants.TXT_COLOR}" />
(snip)
我的目标是从我的常量类中绑定 Constants.TXT_SIZE,从而在 XAML 中拥有一切。
我可以,在 CSharp 中:
lblTest.FontSize=Constants.TXT_SIZE;
我可以做到,在 XAML 中:
TextColor="{x:Static ctes:Constants.TXT_COLOR}"
或者,在 XAML 中:
FontSize="46"
但我不会写,我不明白为什么:
FontSize="{x:Static ctes:Constants.TXT_SIZE}"
它会抛出一个错误:
XFC0009 未找到“FontSize”的属性、BindableProperty 或事件,或者值和属性之间的类型不匹配。
我将常量类型更改为 string 而不是 int 但同样的错误。
知道为什么吗?
【问题讨论】:
-
FontSize的类型是double:)。 -
我觉得自己完全愚蠢。谢谢!
标签: c# xaml xamarin.forms binding