WPF 中 Fluent Ribbon 按钮控件上的图标徽章

Icon Badge on Fluent Ribbon button control in WPF

我是 WPF 新手,想在按钮图片的右上角显示徽章。按钮显示在 Fluent 功能区上。我在这里看到 nir 的答案,看起来不错,但我不知道如何将其应用于按钮控制。

iPhone like red badge notification in a WPF project?

<Page x:Class="Page1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:local="clr-namespace:WpfApplication1"
  mc:Ignorable="d" 
  d:DesignHeight="300" d:DesignWidth="300"
  Title="Page1">
<Page.Resources>
    <Style TargetType="Label" x:Key="CircularLabel">
        <Setter Property="Foreground" Value="White" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="FontSize" Value="13" />
        <Setter Property="FontFamily" Value="Arial" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Label">
                    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
                        <Rectangle Margin="0 3 0 -3" Fill="LightGray" 
                  RadiusX="11" RadiusY="11" Opacity="0.8"/>
                        <Border CornerRadius="11"
                  BorderBrush="DarkGray"
                  BorderThickness="1">
                            <Border
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center" CornerRadius="10"
                    Background="#FFC90000"
                    BorderBrush="White"
                    BorderThickness="2">
                                <Grid>
                                    <ContentPresenter
                        HorizontalAlignment="Center" VerticalAlignment="Center"
                        Content="{TemplateBinding Content}" Margin="5 1 6 1"/>
                                    <Rectangle x:Name="TopShine" RadiusX="9" RadiusY="9"
                        VerticalAlignment="Stretch">
                                        <Rectangle.Fill>
                                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1" Opacity="0.6">
                                                <GradientStop Color="White" Offset="0.2" />
                                                <GradientStop Color="Transparent" Offset="0.7" />
                                            </LinearGradientBrush>
                                        </Rectangle.Fill>
                                    </Rectangle>
                                </Grid>
                            </Border>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Page.Resources>
<Grid>
    <UniformGrid>
        <Label Style="{StaticResource CircularLabel}">2000</Label>
    </UniformGrid>
</Grid>

这是我要应用徽章的按钮控件。

  <Fluent:RibbonGroupBox Fluent:KeyTip.Keys="C" Header="">
                        <Fluent:Button Fluent:KeyTip.Keys="LC" Header=" Transactions" Name="btnTransactions" MinHeight="67" Icon="Images/transferbig.gif" LargeIcon="Images/transfer.gif" FontWeight="Normal"></Fluent:Button>
                    </Fluent:RibbonGroupBox>

请告知是否有任何其他兼容 windows 7、8 和 10 的方法。

我遇到了这个 https://mahapps.com/controls/badged-control.html 我相信它对任何人开放,但不确定它是否适用于 windows 8.

如果我对你的问题理解正确,你可以将 Label 放在 Button 之上,然后使用 Margin 属性 调整其位置,例如:

<Fluent:RibbonGroupBox Fluent:KeyTip.Keys="C" Header="" ClipToBounds="False" Margin="10">
    <Grid>
        <Fluent:Button Fluent:KeyTip.Keys="LC" Header=" Transactions" Name="btnTransactions" MinHeight="67" FontWeight="Normal" />
        <Label Style="{StaticResource CircularLabel}" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,-8,-8,0">2000</Label>
    </Grid>
</Fluent:RibbonGroupBox>

这应该会在 Button 的右上角给你一个徽章。