-1

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

iPhone喜欢WPF项目中的红色徽章通知?

<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。

4

1 回答 1

0

如果我正确理解您的问题,您可以将其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.

于 2018-10-11T13:17:06.900 回答