wpf 如何在 MahApps MetroCircleButtonStyle 图标下添加文本?

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

How to add Text under a MahApps MetroCircleButtonStyle icon?

wpfxamlbuttonmahapps.metro

提问by Orgbrat

I am using the MahApps Metro controls in a WPF application with their FlyOut control on the bottom of the window. I am using their MetroCircleButtonStyle button like so:

我在 WPF 应用程序中使用 MahApps Metro 控件,它们的 FlyOut 控件位于窗口底部。我正在使用他们的 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>

My question is how do I add Text below these icons in the flyout?

我的问题是如何在弹出窗口中的这些图标下方添加文本?

Steve

史蒂夫

回答by Viv

something like:

就像是:

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

enter image description here

在此处输入图片说明

Update:

更新:

MetroCircleButtonStyleby itself does not accomodate for Text outside the Ellipse. It's Templateis pretty much a Grid with 1 cell and 3 children on top of each other(Ellipse, Another Ellipseand top-most is the ContentPresenter). Text inside does not actually respond to any state change either, So text outside with this Style is as good as wrapping the Buttonwithout text with a TextBlockin say a StackPanel.

MetroCircleButtonStyle本身不适应椭圆以外的文本。它Template几乎是一个 Grid,有 1 个单元格和 3 个子组件(Ellipse,另一个Ellipse和最上面的是ContentPresenter)。文本中实际上并不给任何状态变化做出反应要么,所以用这个样式文本之外一样好,因为包裹Button有没有文字TextBlock中说StackPanel

What you're looking for, you could use the AppBarButton. Do note the documentation states, Due to issues with this control, AppBarButton is due to be removed for v1.0so use that as an example and build up your own control with a similar Style. Probably drop the ViewBox, if your Buttonsizes are fixed.

你在找什么,你可以使用AppBarButton。请注意文档状态,Due to issues with this control, AppBarButton is due to be removed for v1.0因此以它为例,并使用类似的Style. ViewBox如果您的Button尺寸是固定的,则可能会删除。

回答by Meigire Triassunu

From Viv'sanswer, you can add margin on the textbox element to push the label down:

Viv 的回答中,您可以在文本框元素上添加边距以将标签向下推:

<Button Width="55"
        Height="55"
        VerticalAlignment="Top"
        Style="{DynamicResource MetroCircleButtonStyle}">
  <StackPanel Orientation="Vertical">
    <Rectangle Width="20"
                Height="20">
      <Rectangle.Fill>
        <VisualBrush Stretch="Fill"
                      Visual="{StaticResource appbar_city}" />
      </Rectangle.Fill>
    </Rectangle>
    <TextBlock Text="Hello" Margin="0, 20, 0, 0" />
  </StackPanel>
</Button>