如何在xamarin表单的XAML中绑定类属性

如何在xamarin表单的XAML中绑定类属性,xaml,binding,xamarin.forms,Xaml,Binding,Xamarin.forms,我的课程安排如下- public static class ColorResources { public static readonly Color ListTextColor = Color.Blue; } 以及任何具有如下控件的xaml文件- <Button Text="Create Account" TextColor="#000000" BackgroundColor="ListTextColor" Clicked="btnCreateA

我的课程安排如下-

public static class ColorResources
    {

        public static readonly Color ListTextColor = Color.Blue;

    }
以及任何具有如下控件的xaml文件-

  <Button Text="Create Account" TextColor="#000000" BackgroundColor="ListTextColor" Clicked="btnCreateAcc_clicked"/>


假设我想要在我的类文件中声明的按钮的背景色。如何实现这一点?

您可以通过在XAML中声明一个新名称空间并使用它来实现这一点

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:color="clr-namespace:MyApp">
<Button Text="Create Account" TextColor="#000000" BackgroundColor="{x:Static color:ColorResources.ListTextColor}" Clicked="btnCreateAcc_clicked"/>

</ContentPage>
确保在XAML中声明的命名空间与类中的命名空间相同。在本例中,是MyApp