views:

118

answers:

2

Hi All,

How can I create Button control which contains a Rectangle object filled with the color represented by the Colors.Aqua?

I have a rectangle

Rectangle rectangle = new Rectangle();
rectangle.Fill = new SolidColorBrush(Colors.Aqua);
rectangle.Width = 100;
rectangle.Height = 50;

and I have a button:

Button button = new Button();
button.Content = "Button";

I can't figure out how to combine these things.

Any ideas?

+1  A: 
button.Content = rectangle;

or in XAML that would be like

<Button>
  <Button.Content>
     <Rectangle Width="100" Height="50">
        <Rectangle.Fill>
           <SolidColorBrush Color="Aqua" />
         </Rectangle.Fill>
      </Rectangle>
  </Button.Content>
</Button>
Yacoder
Thanks. Sometimes you miss the simple things. ;)
Dan Howard
This doesn't include the "Button" text...
Thomas Levesque
If you need a rectangle with the text, you need to use a grouping control, like stackpanel, or grid to put the text over your rectangle (http://social.msdn.microsoft.com/forums/en-US/wpf/thread/47ee2414-e6d4-4c65-b8cc-25d0f0532ace/)
Yacoder
+1  A: 

You can also define a Style in your XAML, set the TargetType to Button, and then set the Background property's Value to "Aqua". Of course, you'll also have to specify the Style for all of the Buttons that you drop into your interface so that they get the desired look.

Dave