在WPF中的RibbonButton中添加textBox

时间:2013-10-03 21:15:17

标签: c# wpf xaml

我正在创建一个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>

1 个答案:

答案 0 :(得分:0)

您需要修改Template的{​​{1}}。

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

Button

右键点击xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon.Primitives;assembly=System.Windows.Controls.Ribbon" Button
这是您应该使用的模板的片段:

Edit 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>... 放在TextBlockStackPanel内,以便按照您的意愿制作。 使用此代码,您可以插入任何您喜欢的控件。

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