0

我遇到了 RibbonToolTips 从功能区中的文本框继承对齐方式的问题。问题是,无论我做什么,我似乎都无法覆盖这种行为。这似乎只体现在文本框和标签上,而 RibbonTextBoxes 似乎不受影响。

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
            };
        }
    }
}
4

1 回答 1

2

试试TextBlock.TextAlignment楼盘怎么样?您可以从MSDN 上的TextBlock.TextAlignment 属性页面了解更多信息。

编辑>>>

抱歉,我以为你可以解决剩下的问题。Style如果您在以下部分中使用它,您可以“这样做” Resources

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

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

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

并像这样设置你的风格:

<Style TargetType="{x:Type Ribbon:RibbonToolTip}">
    <Setter Property="TextBlock.TextAlignment" Value="Left" />
</Style>
于 2013-08-12T14:42:03.173 回答