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

后端 未结 8 1793
情话喂你
情话喂你 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:54

    Important:

    Make sure you're using System.Windows.Media.Brush and not System.Drawing.Brush

    They're not compatible and you'll get binding errors.

    The color enumeration you need to use is also different

    System.Windows.Media.Colors.Aquamarine (class name is Colors) <--- use this one System.Drawing.Color.Aquamarine (class name is Color)

    If in doubt use Snoop and inspect the element's background property to look for binding errors - or just look in your debug log.

提交回复
热议问题