How can I bind a background color in WPF/XAML?

后端 未结 8 1795
情话喂你
情话喂你 2020-12-05 04:01

What do I have to change to the following code so that the background is red, neither of the 2 ways I tried worked:


(source: deviantsart.com)

8条回答
  •  伪装坚强ぢ
    2020-12-05 04:42

    The Background property expects a Brush object, not a string. Change the type of the property to Brush and initialize it thus:

    Background = new SolidColorBrush(Colors.Red);
    

提交回复
热议问题