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

Mal*_*olm 69 wpf button

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

WPF实现这一目标的最佳方法是什么?

马尔科姆

Mat*_*ton 155

我发现Marlett(Windows内置的字体)方便了.

<Button FontFamily="Marlett" FontSize="20" Content="5"/>
<Button FontFamily="Marlett" FontSize="20" Content="6"/>
Run Code Online (Sandbox Code Playgroud)

  • 哇.我知道这不像手绘"三角形"那样"WPF-y",但仍然......没想到下来投票. (7认同)
  • +1修正了我的问题.比每次绘制三角形要好得多.非常方便了解.谢谢! (5认同)
  • 单击开始|运行并键入"charmap" - 然后您可以切换到Marlett并查看.我相信这是Windows 95最初用于呈现其所有UI按钮字形的字体. (3认同)
  • 在Silverlight中,"Webdings"将是用于此的字体. (2认同)

Rhy*_*hys 106

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

  <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>
Run Code Online (Sandbox Code Playgroud)

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

还有一种曲线语法.

  • 左右箭头分别为:数据="M -2 6 L 4 12 L 4 0 Z"数据="M 2 12 L 9 6 L 2 0 Z" (2认同)

Tar*_*ran 33

现在这样做的首选方法是使用Segoe UI Symbol.它取代了Marlett并提供了许多有用的字形.上下都是

<Button FontFamily="Segoe UI Symbol" Content="&#xE110;"/>
<Button FontFamily="Segoe UI Symbol" Content="&#xE1FD;"/>
Run Code Online (Sandbox Code Playgroud)

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

  • 此字体已被Segoe MDL2 Assets for Windows 10取代.为Segoe UI Symbol提供的链接现在引领那里.请注意,Windows 10上不存在Segoe UI符号,Windows 8.1上不存在Segoe MDL2资产. (3认同)

cas*_*One 6

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

<Button>
  <Polygon 
    Points="300,200 450,200 375,300 300,200"
    Stroke="Black">
    <Polygon.Fill>
      <SolidColorBrush Color="Black" />
    </Polygon.Fill>
  </Polygon>
</Button>
Run Code Online (Sandbox Code Playgroud)

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