Configure Syncfusion .NET MAUI Controls Using Visual State Manager (VSM)
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (203)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (211)BoldSign  (13)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (65)Flutter  (132)JavaScript  (219)Microsoft  (118)PDF  (81)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (897)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (127)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (618)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (39)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (501)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (42)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (381)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (17)Web  (582)What's new  (323)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Configure Syncfusion .NET MAUI Controls Using Visual State Manager (VSM)

Configure Syncfusion .NET MAUI Controls Using Visual State Manager (VSM)

The Visual State Manager (VSM) helps developers to specify a control’s appearance based on its visual state. You might have anticipated VSM support in the .NET MAUI platform, as I did.

In this blog, let’s explore what the VSM is and how to configure Syncfusion .NET MAUI controls using it with a couple of examples.

What is the Visual State Manager?

When updating a control’s property based on its state, traditionally, we look for direct properties to set values in various states. Otherwise, we might wait for the control’s state to change before updating it in the code behind.

You can easily do this with the help of the Visual State Manager. It allows you to add code to your XAML file that can change the visual appearance of a control’s view if the control is in any of the common states: normal, disabled, or focused.

For example, consider an Entry control. Here, we are going to change the background color to red when the control is disabled.

<Entry FontSize=”18”>
 <VisualStateManager.VisualStateGroups>
  <VisualStateGroup x:Name=”CommonStates”>
   <VisualState x:Name=”Disabled”>
    <VisualState.Setters>
     <Setter Property=”BackgroundColor” Value=”Red” /> 
    </VisualState.Setters> 
   </VisualState> 
  </VisualStateGroup> 
 </VisualStateManager.VisualStateGroups> 
</Entry>

VSM support in Syncfusion .NET MAUI controls with custom states

Applicable Syncfusion .NET MAUI controls are compatible with VSM. Some controls were built with custom states that, too, can be used for configuration.

Let’s see examples for the Syncfusion .NET MAUI Tab View and Slider controls.

.NET MAUI Tab View

You can change the properties of the .NET MAUI Tab View control using the VSM based on the visual states set in the code. The visual states for which we have customized the properties are selected (custom), normal, and disabled. The selected state is a custom state added in addition to the common states.

Refer to the following code example.

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:tabs="clr-namespace:Syncfusion.Maui.TabView;assembly=Syncfusion.Maui.TabView" 
             x:Class="VSMMAUI.MainPage"> 
 <ContentPage.Resources> 
  <Style TargetType="tabs:SfTabItem"> 
   <Setter Property="VisualStateManager.VisualStateGroups"> <VisualStateGroupList> 
    <VisualStateGroup> 
     <VisualState x:Name="Normal" > 
      <VisualState.Setters> 
       <Setter Property="TextColor" Value="Red" /> 
       <Setter Property="FontSize" Value="12" /> 
      </VisualState.Setters> 
     </VisualState> 
     <VisualState x:Name="Selected"> 
      <VisualState.Setters> 
       <Setter Property="TextColor" Value="#6200EE" /> 
       <Setter Property="FontSize" Value="16" /> 
      </VisualState.Setters> 
     </VisualState> 
    </VisualStateGroup> 
   </VisualStateGroupList> 
   </Setter> 
  </Style> 
 </ContentPage.Resources> 
 <ScrollView> 
  <VerticalStackLayout> 
   <tabs:SfTabView TabWidthMode="Default" HeightRequest="200"> <tabs:SfTabItem Header="Item 1"> 
    <Label Text="Item 1 Content" VerticalOptions="Center" HorizontalOptions="Center" /> 
   </tabs:SfTabItem>
   <tabs:SfTabItem Header="Item 2"> 
    <Label Text="Item 2 Content" VerticalOptions="Center" HorizontalOptions="Center" /> 
   </tabs:SfTabItem>
   <tabs:SfTabItem Header="Item 3" > 
    <Label Text="Item 3 Content" VerticalOptions="Center" HorizontalOptions="Center" /> 
   </tabs:SfTabItem> 
  </VerticalStackLayout> 
 </ScrollView> 
</ContentPage>

Since Item 2 is in the selected state, the corresponding customization property is applied to it.

Configuring Syncfusion .NET MAUI Tab View Properties Using VSM
Configuring Syncfusion .NET MAUI Tab View Properties Using VSM

.NET MAUI Slider

In the .NET MAUI Slider, we can modify the slider track properties based on the visual states using the VSM. The corresponding visual state values are disabled and enabled (default).

Refer to the following code example. In it, we have set false as the value to the IsEnabled property to disable the slider’s UI. The corresponding style is applied to the slider.

<ContentPage.Resources>
 <Style TargetType="sliders:SfSlider">
  <Setter Property="Interval" Value="0.25" />
  <Setter Property="VisualStateManager.VisualStateGroups">
   <VisualStateGroupList>
    <VisualStateGroup>
     <VisualState x:Name="Default">
      <VisualState.Setters>
       <Setter Property="TrackStyle">
        <Setter.Value>
         <sliders:SliderTrackStyle ActiveSize="8"
                                   InactiveSize="6"
                                   ActiveFill="#EE3F3F"
                                   InactiveFill="#F7B1AE"/>
        </Setter.Value>
       </Setter>
      </VisualState.Setters>
     </VisualState>
     <VisualState x:Name="Disabled">
      <VisualState.Setters>
       <Setter Property="TrackStyle">
        <Setter.Value>
         <sliders:SliderTrackStyle ActiveSize="10"
                                   InactiveSize="8"
                                   ActiveFill="Gray"
                                   InactiveFill="LightGray" />
        </Setter.Value>
       </Setter>
      </VisualState.Setters>
     </VisualState>
    </VisualStateGroup>
   </VisualStateGroupList>
  </Setter>
 </Style>
</ContentPage.Resources>
<ContentPage.Content>
 <VerticalStackLayout>
   <Label Text="Enabled Slider" Padding="0,10"/>
   <sliders:SfSlider/>
   <Label Text="Disabled Slider" Padding="0,10"/>
   <sliders:SfSlider IsEnabled="False"/>
 </VerticalStackLayout>
</ContentPage.Content>

Following is the screenshot for this.

Configuring Syncfusion .NET MAUI Slider Properties Using VSM
Configuring Syncfusion .NET MAUI Slider Properties Using VSM

Conclusion

Thanks for reading! In this blog, we saw the use of the Visual State Manager and how to configure the properties of Syncfusion .NET MAUI controls based on their current states using it. We also saw how to alter the properties based on the control’s common and unique states. So, try using VSM to configure controls easily, and leave your feedback in the comments section below!

Download Essential Studio for .NET MAUI to see all its controls in action.

You can also contact us through our support forum, support portal, or feedback portal. We are always happy to assist you!

Test Flight
App Center Badge
Google Play Store Badge
Microsoft Badge
Github Store Badge

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed