How can I create a button which Rectangle object f

2019-07-13 11:49发布

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?

2条回答
冷血范
2楼-- · 2019-07-13 12:05

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-07-13 12:12
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>
查看更多
登录 后发表回答