向 .NET MAUI 中的 Entry 控件添加全局圆角

Sam*_*Sam 4 xamarin xamarin.forms maui .net-maui

在 .NET MAUI 中,有一种很好的方法可以通过文件夹Styles.xaml下的文件全局处理控件的样式Resources/Styles

有没有办法Entry通过文件向所有控件添加圆角Styles.xaml,而不是在文件中单独处理ContentPage XAML

Entry以下是.NET MAUI 应用程序中控件的开箱即用的标准样式。有没有办法在这里添加圆角?据我所知,我们现在通过控制来处理圆角Border。我可以定义一个边框Styles.xaml,然后在样式中引用它以进行Entry控制吗?

<Style TargetType="Entry">
   <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}" />
   <Setter Property="BackgroundColor" Value="{StaticResource FormElementBackground}" />
   <Setter Property="FontFamily" Value="OpenSansRegular"/>
   <Setter Property="FontSize" Value="14" />
   <Setter Property="PlaceholderColor" Value="{AppThemeBinding Light={StaticResource Gray200}, Dark={StaticResource Gray500}}" />
   <Setter Property="VisualStateManager.VisualStateGroups">
      <VisualStateGroupList>
         <VisualStateGroup x:Name="CommonStates">
            <VisualState x:Name="Normal" />
            <VisualState x:Name="Disabled">
               <VisualState.Setters>
                  <Setter Property="TextColor" Value="{AppThemeBinding Light={StaticResource Gray300}, Dark={StaticResource Gray600}}" />
               </VisualState.Setters>
            </VisualState>
         </VisualStateGroup>
      </VisualStateGroupList>
   </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

Arv*_*iya 6

这是向控件添加边框的方法Entry。我们可以使用FrameBorder。我在这里使用Border

<Border Stroke="pink"
        StrokeThickness="2">
    <Entry
            Placeholder="I am textbox">
    </Entry>
</Border>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如果您想为边框提供形状、圆角,请添加Border.StrokeShape

<Border Stroke="pink"
        StrokeThickness="2">
    <Border.StrokeShape>
        <RoundRectangle CornerRadius="0,45,45,0" />
    </Border.StrokeShape>
    <Entry
            Placeholder="I am textbox">
    </Entry>
</Border>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

如果您想在全局范围内使用它,请创建一个自定义控件,例如MyEntry. 添加 aContentView并重复使用它。