テキストボックス内に透かしを表示するためにadornerを使用しています。しかし、ウィンドウのFlowDirectionをRightToLeftに設定すると、adorner(テキストブロック)内のテキストが逆になります!!!
それはバグですか、それとも何かを変更する必要がありますか?
そしてここに装飾者の完全なコードがあります:
namespace Hezareh.Modules.Accounting
{
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
internal class WatermarkAdorner : Adorner
{
#region Private Fields
private readonly ContentPresenter contentPresenter;
#endregion
#region Constructor
public WatermarkAdorner(UIElement adornedElement, object watermark) :
base(adornedElement)
{
this.IsHitTestVisible = false;
this.contentPresenter = new ContentPresenter();
this.contentPresenter.Content = watermark;
this.contentPresenter.Opacity = 0.5;
this.contentPresenter.Margin = new Thickness(Control.Margin.Left + Control.Padding.Left, Control.Margin.Top + Control.Padding.Top, 0, 0);
if (this.Control is ItemsControl && !(this.Control is ComboBox))
{
this.contentPresenter.VerticalAlignment = VerticalAlignment.Center;
this.contentPresenter.HorizontalAlignment = HorizontalAlignment.Center;
}
// Hide the control adorner when the adorned element is hidden
Binding binding = new Binding("IsVisible");
binding.Source = adornedElement;
binding.Converter = new BooleanToVisibilityConverter();
this.SetBinding(VisibilityProperty, binding);
}
#endregion
#region Protected Properties
protected override int VisualChildrenCount
{
get { return 1; }
}
#endregion
#region Private Properties
private Control Control
{
get { return (Control)this.AdornedElement; }
}
#endregion
#region Protected Overrides
protected override Visual GetVisualChild(int index)
{
return this.contentPresenter;
}
protected override Size MeasureOverride(Size constraint)
{
// Here's the secret to getting the adorner to cover the whole control
this.contentPresenter.Measure(Control.RenderSize);
return Control.RenderSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
this.contentPresenter.Arrange(new Rect(finalSize));
return finalSize;
}
#endregion
}
}
そして私はそれを使用します:
<toolkit:AutoCompleteBox Margin="5" Text="" Name="searchCategoriesTextBox">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<i:InvokeCommandAction Command="{Binding SearchCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<local:WatermarkService.Watermark>
<TextBlock TextAlignment="Left" Text="جستجو" FontFamily="Tahoma" Margin="3, -3, 3, 0" />
</local:WatermarkService.Watermark>
</toolkit:AutoCompleteBox>
前もって感謝します :)