代码之家  ›  专栏  ›  技术社区  ›  Zoltán

如何在Maui xaml enty元素中添加装饰后缀?

  •  0
  • Zoltán  · 技术社区  · 1 年前

    我想在我的毛伊岛条目中添加装饰后缀,作为“测试”显示,这怎么可能?

    enter image description here

    1 回复  |  直到 1 年前
        1
  •  0
  •   Liyun Zhang - MSFT    1 年前

    您可以自己自定义这样的控件。

    自定义控件(您可以将其声明为内容视图):

    <Border BackgroundColor="LightBlue">
        <Border.StrokeShape>
            <RoundRectangle CornerRadius="40"/>
        </Border.StrokeShape>
        <Grid ColumnDefinitions="8*,2*" BackgroundColor="Transparent">
            <Entry BackgroundColor="Transparent" Grid.Column="0"/>
            <Label Text="test" BackgroundColor="Transparent" Grid.Column="1" VerticalTextAlignment="Center" HorizontalTextAlignment="Center"/>
        </Grid>
    </Border>
    

    然后禁用条目的下划线和边框:

    对于android和ios,请在App.cs的构造函数中添加以下代码:

    Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("NoBorder", (h, v) =>
                {
    #if ANDROID
                    h.PlatformView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Transparent);
    #elif IOS
                    h.PlatformView.BorderStyle = UIKit.UITextBorderStyle.None;
    #endif
                });
    

    对于windows平台,在下面的App.xaml中添加以下代码 平台/Windows 文件夹

     <maui:MauiWinUIApplication.Resources>
            <Thickness x:Key="TextControlBorderThemeThickness">0</Thickness>
            <Thickness x:Key="TextControlBorderThemeThicknessFocused">0</Thickness>
        </maui:MauiWinUIApplication.Resources>