开发者

How can I create a button which Rectangle object filled with a color in WPF with C#?

开发者 https://www.devze.com 2022-12-11 15:41 出处:网络
How can I create Button control which contains a Rectangle object filled with the color represented by the Colors.Aqua?

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?


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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消