【问题标题】:Static resource colors are not working when setting on button Xamarin forms在按钮 Xamarin 表单上设置时静态资源颜色不起作用
【发布时间】:2021-11-26 17:30:27
【问题描述】:

我正在使用static resource 设置text 和background button 的color,但根本没有显示颜色。

我在共享项目的项目级别添加了Theme.cs 文件。t

public static class Theme
{
    public static Color Application_GreenColor = Color.FromHex("5EC451");
    public static Color Application_RedColor = Color.FromHex("#EC3323");
}

在此xaml 文件下方,在button 上设置颜色

<?xml version="1.0" encoding="utf-8" ?>
<Grid
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:local="clr-namespace:projectName;assembly=projectName"
    xmlns:extensions="clr-namespace:projectName.Extensions.MarkupExtensions;assembly=projectName"
    x:Class="path/projectName">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition
                Height="Auto" />
            <RowDefinition
                Height="Auto" />
        </Grid.RowDefinitions>
        <Grid
            Grid.Row="1"
            Margin="20,20,20,20">
            <Grid.ColumnDefinitions>
                <ColumnDefinition
                    Width="*" />
                <ColumnDefinition
                    Width="*" />
            </Grid.ColumnDefinitions>
           <Button
            Margin="0,0,0,0"
            Command="{Binding ConfirmCardCommand}"
            Text="CardOperationsView"
            FontSize="Medium"
            CornerRadius="30"
            ContentLayout="Right"
            TextColor="{x:Static local:Theme.Application_PrimaryButtonTextColor}"
            Grid.Column="1"
            HorizontalOptions="FillAndExpand"
            VerticalOptions="Center"
            BackgroundColor="{x:Static local:Theme.Application_RedColor}" />
        </Grid>
    </Grid>
</Grid>

上面的 UI 是用于弹出的。这就是弹出窗口的打开方式

private async Task ShowCardDialogAsync()
{
    _CardPopup = await DialogHelper.ShowCustomBottomPopupAsync(new CardPopupTemplate(), this);
}

来自 xaml Button 不是任何背景和文本颜色。我该如何解决这个问题?

【问题讨论】:

  • 嗨!只是为了确保,如果您的 Theme.cs 不是共享项目。它有效吗?另外,您的项目是否引用了共享项目?

标签: xamarin xamarin.forms styles staticresource


【解决方案1】:

做了一个小项目,但颜色在按钮中显示为 BackgroundColor 红色。

你添加了这个吗?

xmlns:local="clr-namespace:ColorbindingClass"

使用您自己的项目名称更改 ColorbindingClass。 不断出错。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-31
    • 2018-05-16
    • 1970-01-01
    相关资源
    最近更新 更多