How do you color a rectangle in C# that has been declared in

Views for WPF Forum

Posted 14 years ago by Xev Xarzu
Version: 10.1.0522
How do you color a rectangle in C# that has been declared in XAML in WPF?

There is a rectangle control in XAML. In my C# code there are times in which it would be nice to fill the background color. How does one do this?

The rectangle has a text block nested inside. The Fill works to color the whole rectangle but it also blocks out the text. On the other hand, using the stroke first colors the rectangle and I can modify the enclosed test but the rectangle does not have a boarder.

The way to do it might be to bind the Rectangle background colouur to a property and use INotifyPropertyChanged to trigger the update of the colour based on the change.

How do I bind the Rectangle background colour to a property?

[Modified at 05/22/2010 07:00 AM]

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA

Our support is limited to our products. If you have general WPF questions, they should be posted on Microsoft's forum ( or a third-party forum (such as

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.