【发布时间】: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