RibbonToolTip 从文本框继承对齐方式 [英] RibbonToolTip is inheriting alignment from a textbox

查看:23
本文介绍了RibbonToolTip 从文本框继承对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RibbonToolTips 从功能区中的文本框继承对齐方式时遇到问题.问题是无论我做什么,我似乎都无法覆盖这种行为.这似乎仅适用于文本框和标签,而 RibbonTextBox 似乎不受影响.

I'm having an issue with RibbonToolTips inheriting alignment from a textbox in the ribbon. The problem is that I can't seem to override this behavior no matter what I do. This only seems to manifest for Textboxes and Labels and RibbonTextBoxes seem to be unaffected.

XAML:

<RibbonWindow x:Class="RibbonToolTipTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid x:Name="LayoutRoot">
   <Ribbon Title="WPF Ribbon" x:Name="Ribbon">
       <RibbonTab>
           <RibbonGroup Width="300">
               <StackPanel Orientation="Horizontal">
                    <TextBox Text="This is a test" TextAlignment="Right" x:Name="RegularLabel" />
                    <TextBox Width="200" TextAlignment="Left"  x:Name="RegularTextBox"/>
                </StackPanel>
                <RibbonTextBox Width="200"
                               ToolTipTitle="Title"
                               ToolTipDescription="The moon was shining sulkily, Because she thought the sun Had got no business to be there After the day was done — &quot;It's very rude of him,&quot; she said, &quot;To come and spoil the fun.&quot;" 
                               Label="Label" />
           </RibbonGroup>
       </RibbonTab>
   </Ribbon>
</Grid>

代码隐藏:

using System.Windows.Controls.Ribbon;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RibbonToolTipTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : RibbonWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            RegularTextBox.ToolTip = RegularLabel.ToolTip = new RibbonToolTip()
            {
                Title = "Title",
                Description =
                    "The sun was shining on the sea, Shining with all his might: He did his very best to make The billows smooth and bright — And this was odd, because it was The middle of the night. ",
                HorizontalContentAlignment = HorizontalAlignment.Left,
                HorizontalAlignment = HorizontalAlignment.Left
            };
        }
    }
}

推荐答案

试试 TextBlock.TextAlignment 属性怎么样?您可以从 TextBlock.TextAlignment 属性页面.

How about trying the TextBlock.TextAlignment property? You can find out more from the TextBlock.TextAlignment Property page at MSDN.

编辑 >>>

抱歉,我以为你可以解决其余的问题.如果您在 Resources 部分的 Style 中使用它,您可以这样做":

Sorry, I assumed that you could work out the rest. You could 'do that' if you used it in a Style in the Resources section:

<Style TargetType="{x:Type RibbonToolTip}">
    <Setter Property="TextBlock.TextAlignment" Value="Left" />
</Style>

对于使用早于 .NET 4.5 的 .NET Frameworks 的用户,您可以从 Microsoft 的 下载中心.安装后,您可以添加一个 XML 命名空间:

For users using .NET Frameworks older than .NET 4.5, you can download the RibbonControlLibrary dlls from Microsoft's Download Center. Once installed, you can then add an XML namespace:

xmlns:Ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"

然后像这样设置你的风格:

And set up your style like this:

<Style TargetType="{x:Type Ribbon:RibbonToolTip}">
    <Setter Property="TextBlock.TextAlignment" Value="Left" />
</Style>

这篇关于RibbonToolTip 从文本框继承对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆