How can I set a WPF control's color to a system color programmatically, so that it updates on color scheme changes?

后端 未结 4 936
眼角桃花
眼角桃花 2020-12-16 09:30

How can I do this in WPF\'s code-behind?


4条回答
  •  离开以前
    2020-12-16 10:21

    I just found an ugly solution:

    grid1.SetResourceReference(
        Control.BackgroundProperty,
        SystemColors.DesktopBrushKey);
    

    I hope someone will post a better one (I'd like to see something like grid1.Background = BackgroundBrush, because the syntax of SetResourceReference is a step backwards from Windows Forms).

提交回复
热议问题