Home > Net >  Override the internal margins for a WinUI ToggleSwitch
Override the internal margins for a WinUI ToggleSwitch

Time:12-10

I'm looking to use a ToggleSwitch in WinUI that has no margin around it. In the template there are two settings called ToggleSwitchPreContentMargin and ToggleSwitchPostContentMargin. I'm looking to override these in my XAML page. I can override them like this, and it works great:

<ToggleSwitch>
    <ToggleSwitch.Resources>
        <x:Double x:Key="ToggleSwitchPreContentMargin">0</x:Double>
        <x:Double x:Key="ToggleSwitchPostContentMargin">0</x:Double>
    </ToggleSwitch.Resources>
</ToggleSwitch>

But I would like to set these using a style instead (or any reusable way) so I can assign this only to the ToggleSwitches where I would like this to be applicable, but I don't want to specify the resources like above for each and every toggle switch.

CodePudding user response:

I guess I'd choose between these 2 options:

A. Create a user control with a ToggleSwitch, expose the dependency properties you need and override the margins inside it.

B. Create style with a key, bring the entire template and override the margins inside it.

  • Related