1

我正在创建一个 WPF。我在 WPF 中使用功能区。有没有办法创建一个里面有一个 textBlock 的 RibbonButton?这是我正在使用的代码。我想在 baggerActiveBtn 中放置一个 textBlock。

<Ribbon x:Name="RibbonWin"
        SelectedIndex="0"
        Margin="81,23,-81,77"
        Grid.RowSpan="2">
  <RibbonTab Header="Home"
             KeyTip="H">
    <!-- Home  group-->
    <RibbonGroup x:Name="MenuGroup">
      <RibbonButton Name="baggerActiveBtn"
                    Height="67"
                    Margin="368,36,86,0"
                    MouseOverBorderBrush="#FFFFC500"
                    VerticalAlignment="Top"
                    BorderBrush="Red"
                    Click="test123">

        <RibbonButton.MouseOverBackground>
          <LinearGradientBrush EndPoint="0.5,1"
                               StartPoint="0.5,0">
            <GradientStop Color="#FFFFC500"
                          Offset="0" />
            <GradientStop Color="White"
                          Offset="1" />
          </LinearGradientBrush>
        </RibbonButton.MouseOverBackground>

      </RibbonButton>
    </RibbonGroup>
  </RibbonTab>
</Ribbon>
4

1 回答 1

0

您需要编辑Template.Button

首先,在您的 XAML 文件中包含此 xmlns:

xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon.Primitives;assembly=System.Windows.Controls.Ribbon"

右键单击您的ButtonEdit Template -> Edit a Copy...
这是您应该处理的模板片段:

...<Border x:Name="OuterBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding CornerRadius}" SnapsToDevicePixels="True">
            <Border x:Name="InnerBorder" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}" Padding="{TemplateBinding Padding}">
                <StackPanel x:Name="StackPanel">
                    <Image x:Name="PART_Image" RenderOptions.BitmapScalingMode="NearestNeighbor" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Height="32" Margin="{DynamicResource {ComponentResourceKey ResourceId=LargeImageMargin, TypeInTargetAssembly={x:Type Ribbon}}}" Source="{TemplateBinding LargeImageSource}" VerticalAlignment="Center" Width="32"/>
                    <Grid x:Name="Grid" HorizontalAlignment="Center" VerticalAlignment="Center">
                        <RibbonTwoLineText x:Name="TwoLineText" HorizontalAlignment="Center" LineStackingStrategy="BlockLineHeight" LineHeight="13" Margin="1,1,1,0" TextAlignment="Center" Text="{TemplateBinding Label}" VerticalAlignment="Top"/>
                    </Grid>
                </StackPanel>
            </Border>
        </Border>...

你应该把你TextBlock放在里面,StackPanel或者Grid按照你的意愿去做。使用此代码,您可以插入您喜欢的任何控件。

这至少应该指导你!祝你好运。

于 2013-10-03T21:31:04.577 回答