Override default properties of .Net Maui Switch Control to Yes/No

Ronald Rex 1,666 Reputation points
2023-06-30T20:49:56.66+00:00

Hi Friends. Can I Override default properties of Off/ On in .Net Maui Switch Control. I want to use the values Yes/No instead. Thanks in advance

Developer technologies .NET .NET MAUI
Developer technologies C#
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-07-04T02:15:53.0066667+00:00

    Hello,

    After testing, only the switch control on Windows platforms will display the word On/Off.

    You could refer to the following code snippet to change the text of the Switch control in the page to Yes/No.

    // in xaml
    <Switch x:Name="test_switch" IsToggled="true"/>
    
    // in code behind
    protected override void OnHandlerChanged()
    {
        base.OnHandlerChanged();
    #if WINDOWS
        var s = test_switch.Handler.PlatformView as ToggleSwitch;
        if (s != null)
        {
            s.OffContent = "No";
            s.OnContent = "Yes";
        }
    #endif
    }
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.