Setting or modifying ThemeResource in code

后端 未结 5 658
野趣味
野趣味 2021-02-06 04:14

My questions is very specific to ThemeResources in a Windows 10 Store App. Unfortunately several things available in \"classic\" WPF are different or not available here.

5条回答
  •  广开言路
    2021-02-06 04:59

    There is a way how to kinda set ThemeResource in code... I've tested it only on W10 Creators Update so it may not work on older versions, but you can create your own resource that is referencing the original ThemeResource you want to use and then use this resource:

    XAML:

    
    

    C#:

    element.BorderBrush = (SolidColorBrush)Resources["MyBorderBrush"];
    

    The border color of element will be the same as the Accent Color selected in Windows Settings and it will change even when your app is running and user changes it.

提交回复
热议问题