我正在学习毛伊语,这个装订的东西还是很棘手的.

我有一个这样的XAML:

<ScrollView Grid.Row="1"
            Orientation="Horizontal"
            HorizontalOptions="FillAndExpand"
            HorizontalScrollBarVisibility="Default"
            VerticalOptions="Center">
    <HorizontalStackLayout RadioButtonGroup.GroupName="MenuCategories"
                           x:Name="foodTypeStack"
                           VerticalOptions="Start"
                           Spacing="3">
        <BindableLayout.ItemTemplate>
            <DataTemplate>
                <RadioButton Content="{Binding .}">
                    <RadioButton.ControlTemplate>
                        <ControlTemplate>
                            <Grid>

                                <Border x:Name="dishTypeContainer"
                                        MinimumWidthRequest="80"
                                        MaximumHeightRequest="140"
                                        Padding="8,0,8,0"
                                        Stroke="Transparent">
                                    <Border.StrokeShape>
                                        <RoundRectangle CornerRadius="20,20,20,20" />
                                    </Border.StrokeShape>

                                    <Label x:Name="dishTypeTextLabel"
                                           HorizontalOptions="Center"
                                           Text="{TemplateBinding Content.Name}"
                                           FontFamily="Icons"
                                           VerticalOptions="Center" />
                                </Border>

                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroupList>
                                        <VisualStateGroup x:Name="CheckedStates">
                                            <VisualState x:Name="Checked">
                                                <VisualState.Setters>
                                                    <Setter TargetName="dishTypeTextLabel"
                                                            Property="Label.TextColor"
                                                            Value="WhiteSmoke" />
                                                    <Setter TargetName="dishTypeContainer"
                                                            Property="Border.BackgroundColor"
                                                            Value="{StaticResource DarkSeaBlue}" />
                                                </VisualState.Setters>
                                            </VisualState>
                                            <VisualState x:Name="Unchecked">
                                                <VisualState.Setters>
                                                    <Setter TargetName="dishTypeTextLabel"
                                                            Property="Label.TextColor"
                                                            Value="{StaticResource LightGray}" />
                                                    <Setter TargetName="dishTypeContainer"
                                                            Property="Border.BackgroundColor"
                                                            Value="WhiteSmoke" />
                                                </VisualState.Setters>
                                            </VisualState>
                                        </VisualStateGroup>
                                    </VisualStateGroupList>
                                </VisualStateManager.VisualStateGroups>
                            </Grid>
                        </ControlTemplate>
                    </RadioButton.ControlTemplate>
                </RadioButton>
            </DataTemplate>
        </BindableLayout.ItemTemplate>
    </HorizontalStackLayout>
</ScrollView>

在.cs文件中,我有这种类型的绑定:

protected override async void OnAppearing()
{
    base.OnAppearing();
    var foodTypes = await menuDatabase.GetFoodTypeListAsync();
    BindableLayout.SetItemsSource(foodTypeStack, foodTypes);
}

单选按钮模板上使用的标签的Icons字体是Fontello字体.

问题是,该标签中的字体不适用.在我开始使用绑定表达式之前,它就起作用了.

帖子主题:Re:Колибри

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .ConfigureFonts(fonts =>
        {
            fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
            fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            fonts.AddFont("Fontello.ttf", "Icons");
            fonts.AddFont("Rubik-Light.ttf", "RubikLight");
            fonts.AddFont("Rubik-Regular.ttf", "RubikRegular");
        });

    builder.Services.AddSingleton<MauiAppTestDatabase>();

#if DEBUG
    builder.Logging.AddDebug();
#endif
    return builder.Build();
}

这是标签上使用的字符串之一:

&#xE801; Drink

推荐答案

在C#中定义字体图标字符串时,需要使用以下Unicode表示法:

public string MyIcon { get; } = "\ue801";

这应该等同于用XAML编写&#xE801;.

这样,在绑定表达式中使用字体图标时,您应该能够看到字体图标,而不是字符串.

您可以在此处通过上传字体https://andreinitescu.github.io/IconFont2Code/来判断每个图标的C#Unicode表示法

102 that 100 is not a valid value for a label using an icon font, because the 101 part is not found in the font. Depending on the platform, it may still be shown, but it's not guaranteed. If you need to display an icon and text, you should work with two separate labels each with a different FontFamily set - one for the icon and one for the text.

Csharp相关问答推荐

LINQ无法翻译SQLFunctions方法

. NET 8使用COM向VB6公开

返回TyedResults.BadRequest<;字符串>;时问题详细信息不起作用

不带身份的Blazor服务器.Net 8 Cookie身份验证

有没有办法在WPF文本框中添加复制事件的处理程序?

需要在重新启动ApplicartionPool或IIS后启动/唤醒API的帮助

如何将不同类型的扩展参数的javascript函数转换成C#风格?

UWP中的任务和界面

当前的文化决定了错误的文化

Cosmos SDK和Newtonsoft对静态只读记录的可能Mutations

在.NET MAUI.NET 8中如何防止按钮点击时出现灰色反馈

当前代码Cosmos DB 3.37.1:PartitionKey key key mismatch exception

异步任务导致内存泄漏

Content WithTargetPath实际上是有效的MSBuild项吗?

用于获取字符串的最后12个字符的正则表达式(空格除外)

VS代码扩展无法在新版本扩展C#中运行从v2.10.28开始

S,在.NET核心控制台应用程序中,AddScope和AddSingleton有什么不同?

有没有更好的方法来使用LINQ获取整行的计算组

如何根据分割文本的块数来计算文本的大小?

使用生产环境调试我的应用程序的快速方法