WPF - 使用标准按钮创建带有向上和向下箭头的按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/432384/
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-08 19:57:21  来源:igfitidea点击:

WPF - Create buttons with up and down arrows using standard buttons

wpfbutton

提问by Malcolm

I want to create some up and down buttons using the standard button background but with black arrows.

我想使用标准按钮背景但带有黑色箭头创建一些向上和向下按钮。

What is the best way to accomplish this with WPF??

使用 WPF 完成此任务的最佳方法是什么?

Malcolm

马尔科姆

回答by Matt Hamilton

I find Marlett (a font built into Windows) handy for that sort of thing.

我发现 Marlett(一种内置于 Windows 的字体)对这类事情很方便。

<Button FontFamily="Marlett" FontSize="20" Content="5"/>
<Button FontFamily="Marlett" FontSize="20" Content="6"/>

Output:

输出:

enter image description here

在此处输入图片说明

回答by Rhys

No discussion on this subject would be complete without mentioning the geometry mini-language (or Path Markup Syntax) for a more compact shape definition:-

如果不提及几何迷你语言(或路径标记语法)以获得更紧凑的形状定义,则有关此主题的讨论将是完整的:-

  <Button>
    <Path Fill="Black" Data="M 0 6 L 12 6 L 6 0 Z"/>
  </Button>
  <Button>
    <Path Fill="Black" Data="M 0 0 L 6 6 L 12 0 Z"/>
  </Button>

The first describes a Move to 0,6 Line to 12,6 Line to 6,0 and then close the shape (Z).

第一个描述了移动到 0,6 线到 12,6 线到 6,0 然后关闭形状 (Z)。

There is also a curve syntax.

还有一个曲线语法。

回答by Taran

The preferred way to do this now is using Segoe UI Symbol. It replaces Marlett and provides many useful glyphs. Up and down would be

现在执行此操作的首选方法是使用Segoe UI Symbol。它取代了 Marlett 并提供了许多有用的字形。上下会

<Button FontFamily="Segoe UI Symbol" Content="&#xE110;"/>
<Button FontFamily="Segoe UI Symbol" Content="&#xE1FD;"/>

Which renders as:

呈现为:

enter image description here

在此处输入图片说明

This font is pre-installed on all versions of windows 7+.

此字体已预装在所有版本的 Windows 7+ 上。

回答by casperOne

You can create a Polygonwhich represents your up and down triangles and then set them to be the content of the buttons:

您可以创建一个Polygon代表您的上下三角形,然后将它们设置为按钮的内容:

<Button>
  <Polygon 
    Points="300,200 450,200 375,300 300,200"
    Stroke="Black">
    <Polygon.Fill>
      <SolidColorBrush Color="Black" />
    </Polygon.Fill>
  </Polygon>
</Button>

You can tweak these to draw different figured, but that's generally the XAML you would use for basic geometry.

您可以调整这些以绘制不同的图形,但这通常是您用于基本几何图形的 XAML。

回答by Pinga

If you would like to have an arrow with base rectangle you can use this sample...

如果您想要一个带有基本矩形的箭头,您可以使用此示例...

<Button >
   <Polygon   Stretch="Fill"  Fill="Black" Points="0,0 0,30 0,10 30,10 30,-10 45,10 30,30 30,20 0,20 0,0 30,0 30,10 0,10" />
</Button>