2

In .NET MAUI, there's a nice way to handle styling of controls globally through the Styles.xaml file under Resources/Styles folder.

Is there a way to add rounded corners to all Entry controls through the Styles.xaml file rather than handle it individually in ContentPage XAML files?

Here's the standard styling, out of the box, for Entry controls in a .NET MAUI app. Is there a way to add rounded corners to this here? I understand we now handle rounded corners through Border control. Could I define a border in Styles.xaml and then reference it in styles for Entry control?

<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>
Sam
  • 26,817
  • 58
  • 206
  • 383
  • 1
    One way to achieve it with shared code is creating a custom control, but you should redeclare all the entry properties you need. Otherwise you may want to use [handlers](https://learn.microsoft.com/en-us/dotnet/maui/user-interface/handlers/customize). – Riccardo Minato Jun 18 '22 at 17:05
  • 1
    Make your own custom control, and use that. So far, creating maui `handlers` (that do anything more than set a few properties) seems to be [surprisingly involved](https://stackoverflow.com/a/72412170/199364). The code I show in question isn't bad - but look at the actual github repo: I had to copy a number of additional files from Maui sources, to re-use Entry's functionality. – ToolmakerSteve Jun 21 '22 at 03:24

0 Answers0