如何使用 C# 在 WPF 中创建一个用颜色填充的 Rectangle 对象的按钮? [英] How can I create a button which Rectangle object filled with a color in WPF with C#?

查看:121
本文介绍了如何使用 C# 在 WPF 中创建一个用颜色填充的 Rectangle 对象的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建包含填充了 Colors.Aqua 表示的颜色的 Rectangle 对象的 Button 控件?

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

我有一个矩形

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

我有一个按钮:

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

我不知道如何组合这些东西.

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

有什么想法吗?

推荐答案

button.Content = rectangle;

或者在 XAML 中,就像

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>

这篇关于如何使用 C# 在 WPF 中创建一个用颜色填充的 Rectangle 对象的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆