WinUI3-CustomControl: Cannot derived from sealed type 'ToggleSwitch'

Minh Van 171 Reputation points
2023-01-31T03:19:10.3466667+00:00

Hi,

I want to create a custom control for toggle switch, but I only can derive from Control class rather than Toggle Switch class. I know that this is a sealed class, but any workaround or another approach for this? I want to dispose all dependency properties from ToggleSwitch to CustomToggleSwitch.

User's image

I know that it is better to use Style as a property but my project requires a control.

User's image

Thanks.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
725 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 11,336 Reputation points Microsoft Vendor
    2023-01-31T05:47:56.8566667+00:00

    Hello,

    Welcome to Microsoft Q&A!

    You can implement your CustomToggleSwitch based on ToggleButton_themeresources.xaml.

    Thank you.

    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.