Can we style the Hint Label in our styles.xaml?

I would like to implement global styling for our SfTextInputLayout but cannot find a way to do this as a global style. Here is what I am attempting to do in the Styles.xaml file: 


<Style TargetType="sfCore:SfTextInputLayout">
    <Setter Property="TrailingViewPosition" Value="Inside" />
    <Setter Property="ContainerType" Value="Outlined" />
    <Setter Property="Stroke" Value="{DynamicResource s1Gray}" />
    <Setter Property="ContainerBackground" Value="White" />
    <Setter Property="HintLabelStyle">
        <Setter.Value>
        <Style TargetType="Label">
            <Setter Property="FontFamily" Value="NunitoSans-Regular" />
                <Setter Property="FontSize" Value="{DynamicResource fontLarge}" />
                <Setter Property="TextColor" Value="{DynamicResource s1Gray}" />
            </Style>
        </Setter.Value>
    </Setter>
</Style>

3 Replies

BV Brundha Velusamy Syncfusion Team January 8, 2024 02:01 PM UTC

Hi Travis,


We can set style for the HintLabel in the SfTextInputLayout component as shown in the below provided code snippet. Also we recommend utilize StaticResource for the LableStyle properties instead of DynamicResource. The inner layer dynamic resource is not functioning as expected. We have already reported this issue to the Maui framework team, and you can find more details on the issue link below:


Link:  https://github.com/dotnet/maui/issues/3745


If you wish to use DynamicResource for Hint TextColor, Currently, we only have the option to modify the full HintLableStyle at the sample level. We have created the sample based on this and attached it for your reference. Please review the sample and let us know if you require any other details.


Please refer the below code snippet for this,

<sfCore:LabelStyle  x:Key="textInputHintLabelStyle"

 TextColor="{AppThemeBinding Light={StaticResource Magenta}, Dark={StaticResource PrimaryDark}}"

 FontSize="16"/>

<Style TargetType="sfCore:SfTextInputLayout" ApplyToDerivedTypes="True" >

    <Setter Property="ContainerBackground" Value="Transparent" />

    <Setter Property="BackgroundColor"  Value="Transparent" />

    <Setter Property="HeightRequest" Value="60"/>

    <Setter Property="HintLabelStyle" Value="{DynamicResource textInputHintLabelStyle}"/>

   

</Style>


Please refer the below KB for customize the HintLabelStyle in Styles.xaml file

Link: https://support.syncfusion.com/kb/article/13581/how-to-customize-the-border-and-labels-in-net-maui-textinputlayout


Regards,

Brundha V


Attachment: TextInputLayout_6d5b6d13.zip


DM Daniel Mamnev January 8, 2024 08:09 PM UTC

Hi, could you provide a sample where the LabelStyle font size is a dynamic resource that is set programmatically? 

<x:Double x:Key="fontLarge">0</x:Double>

 <sfCore:LabelStyle  
  x:Key="textInputHintLabelStyle"
  FontSize="{DynamicResource fontLarge}"
  FontFamily="NunitoSans-Regular"
  TextColor="{StaticResource s1Gray}"/>
 <Style TargetType="sfCore:SfTextInputLayout" ApplyToDerivedTypes="True">
     <Setter Property="TrailingViewPosition" Value="Inside" />
     <Setter Property="ContainerType" Value="Outlined" />
     <Setter Property="Stroke" Value="{DynamicResource s1Gray}" />
     <Setter Property="ContainerBackground" Value="White" />
     <Setter Property="HintLabelStyle" Value="{DynamicResource textInputHintLabelStyle}"/>
 </Style>


Then in a class I run the code below:

 This does not apply the font size.

The problem we are running intois that we want to set the font size depending on a user setting inour application for the font sizes throughout the application.


   public void Apply()
   {
      
       App.Current.Resources.MergedDictionaries.Last()["fontLarge"]=20;
    }



BV Brundha Velusamy Syncfusion Team January 9, 2024 10:02 AM UTC

Hi Daniel,


As we mentioned earlier, the dynamic resource is experiencing functionality issues, specifically related to inner layer properties within the framework. Consequently, attempting to set dynamic resources directly for the LabelStyle properties may not yield the expected results due to this underlying framework issue.


Issue Link:  https://github.com/dotnet/maui/issues/3745


If you wish to use DynamicResource for LableStyle properties, Currently, we only have the option to modify the full HintLableStyle as DynamicResource at the sample level. We have modified the sample based on this and attached it for your reference. Please review the sample and let us know if you require any other details.


Please refer the below code snippet for this,

<sfCore:LabelStyle  x:Key="textInputHintLabelStyle"

 TextColor="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource PrimaryDark}}"

 FontSize="{StaticResource FontLarge}"/>

<Style TargetType="sfCore:SfTextInputLayout" ApplyToDerivedTypes="True" >

    <Setter Property="HintLabelStyle" Value="{DynamicResource textInputHintLabelStyle}"/>

   

</Style>


Regards,

Brundha V


Attachment: TextInputLayout_d616819a.zip

Loader.
Up arrow icon