I have a switch control in .Net Maui :
<Switch IsToggled="true" Grid.Row="3" Grid.Column="1" VerticalOptions="Center"/>
By default it shows a label "on/off" based on it's state. I want it to show nothing.
Is there any way to hide/remove it?
I have a switch control in .Net Maui :
<Switch IsToggled="true" Grid.Row="3" Grid.Column="1" VerticalOptions="Center"/>
By default it shows a label "on/off" based on it's state. I want it to show nothing.
Is there any way to hide/remove it?
Unfortunately the Maui switch control have SwitchOnVisualState \ SwitchOffVisualState content set to constant strings and you can't override it yet apparently.
You can however override the ToggleSwitch class style in WinUI through the App.xaml file.
Project\Platforms\Windows\App.xaml
It should look like this.
<maui:MauiWinUIApplication
x:Class="Project.Client.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:Project.Client.WinUI">
<maui:MauiWinUIApplication.Resources>
<ResourceDictionary>
<!-- ToggleSwitch : Turn off ON/OFF label -->
<Style TargetType="ToggleSwitch">
<Setter Property="OffContent" Value=" " />
<Setter Property="OnContent" Value=" " />
<Setter Property="Margin" Value="0,0,-110,0" />
</Style>
</ResourceDictionary>
</maui:MauiWinUIApplication.Resources>
</maui:MauiWinUIApplication>
See?
Please check the solution for this issue here https://github.com/dotnet/maui/issues/6177 I have tried one solution and it is working I have used Absolute Layout. As Absolute Layout gives you option to specify child's width . I have given 60 as width for the Switch controll. And it show only the Switch not On/Off text next to it. And also checked by resizing the window , all is working fine. The On/Off Text doesn't Appear.