在 WPF 中的 RibbonButton 内添加文本框 [英] Adding a textBox inside a RibbonButton in a WPF
问题描述
我正在创建一个 WPF.我在 WPF 中使用功能区.有没有办法创建一个里面有一个 textBlock 的 RibbonButton?这是我正在使用的代码.我想在 baggerActiveBtn 中放置一个 textBlock.
I'm creating a WPF. I'm using a ribbon in the WPF. Is there a way to create a RibbonButton that has a textBlock inside of it? Here is the code I'm using. I'd like to place a textBlock inside the baggerActiveBtn.
<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>
推荐答案
您需要编辑 Button
的 Template
.
首先,在您的 XAML 文件中包含此 xmlns:
First thing, include this xmlns in your XAML file:
xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon.Primitives;assembly=System.Windows.Controls.Ribbon"
右击你的Button
,Edit Template ->编辑副本...
这是您应该处理的模板片段:
Right click your Button
, Edit Template -> Edit a Copy...
This is a snippet of the template you should work on:
...<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
中以按照您的意愿制作.使用此代码,您可以插入任何您喜欢的控件.
You should place you TextBlock
inside the StackPanel
or Grid
to make it as you wish.
With this code you can insert whatever Control you like.
这至少应该指导你!祝你好运.
This should at least guide you! Good luck.
这篇关于在 WPF 中的 RibbonButton 内添加文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!