wpf 地铁圈按钮背景

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17764537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:15:11  来源:igfitidea点击:

Metro Circle Button Background

c#wpfxamlbutton

提问by Altamash Shaikh

I am using Buttonwith MetroCircleButtonStylewith MetroUIin WPF. How can I change the background of this Button?

我使用ButtonMetroCircleButtonStyleMetroUI在WPF。我怎样才能改变这个背景Button

Code:

代码:

<Button Background="Green" 
        Name="button2"
        Style="{DynamicResource MetroCircleButtonStyle}" 
        Width="50" Height="50" />

Currently the button look like this but i want the one on the right:

目前按钮看起来像这样,但我想要右边的按钮:

enter image description here

在此处输入图片说明

回答by Viv

If you get the Git-Sourcefor MahApps.Metro, It has a few demo targets that show you the normal usage of almost all their controls.

如果你得到的Git-来源MahApps.Metro,它有告诉你几乎所有的控件的正常使用几个演示目标。

In MetroDemotarget under MainWindow.xamltheir usage of MetroCircleButtonStylelooks like:

MetroDemo目标下MainWindow.xaml他们的用法MetroCircleButtonStyle看起来像:

<Button Width="55"
        Height="55"
        VerticalAlignment="Top"
        Style="{DynamicResource MetroCircleButtonStyle}">
  <Rectangle Width="20"
              Height="20">
    <Rectangle.Fill>
      <VisualBrush Stretch="Fill"
                    Visual="{StaticResource appbar_city}" />
    </Rectangle.Fill>
  </Rectangle>

</Button>

In your case, you'd prolly want the "appbar_add" resource

在您的情况下,您可能会想要“appbar_add”资源

<Button Width="55"
        Height="55"
        VerticalAlignment="Top"
        Style="{DynamicResource MetroCircleButtonStyle}">
  <Rectangle Width="20"
              Height="20">
    <Rectangle.Fill>
      <VisualBrush Stretch="Fill"
                    Visual="{StaticResource appbar_add}" />
    </Rectangle.Fill>
  </Rectangle>
</Button>

Note you need to add the ResourceDictionarycontaining the Canvas's for this. It can also be got from NuGet Packages (MahApps.Metro.Resources).

请注意,您需要为此添加ResourceDictionary包含 的Canvas。它也可以从 NuGet 包 ( MahApps.Metro.Resources) 中获得。

Concept is pretty much apply the Canvaspath of your choosing(which you get quite a few of as listed in the docs) as the VisualBrushand you should be sorted.

概念几乎适用于Canvas您选择的路径(您会得到很多,如文档中所列),VisualBrush并且您应该进行排序。

回答by Stan

I think you need to design your own custom button but it's pretty easy.

我认为您需要设计自己的自定义按钮,但这很容易。

Hereare explained plenty of ways you can do that.

这里解释了很多方法可以做到这一点。