gpt4 book ai didi

c# - WPF 中的 BUG?当 FlowDirection 为 RightToLeft 时,Adorner 中的 TextBlock 会显示反转文本

转载 作者:行者123 更新时间:2023-11-30 17:13:37 25 4
gpt4 key购买 nike

我正在使用装饰器在文本框中显示水印。但是当我将窗口的 F​​lowDirection 设置为 RightToLeft 时,装饰器内的文本(即文本 block )是相反的!!!

这是一个错误还是我应该改变什么?

enter image description here

这是装饰器的完整代码:

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>

提前致谢:)

最佳答案

好吧,最后我找到了另一个解决方案来解决这个问题。我使用 RenderTransofrm 像这样在装饰器内部镜像控制:

    <local:WatermarkService.Watermark>
<TextBlock Name="watermarkTextBox"
Text="{x:Static resources:Resources.SearchCodingTreeView}"
RenderTransformOrigin="0.5,0.5" TextAlignment="Right">
<TextBlock.RenderTransform>
<ScaleTransform ScaleX="-1" />
</TextBlock.RenderTransform>
</TextBlock>
</local:WatermarkService.Watermark>

RenderTransformOrigin="0.5,0.5" 将枢轴置于控制中心并 ScaleX="-1" 水平翻转它。

关于c# - WPF 中的 BUG?当 FlowDirection 为 RightToLeft 时,Adorner 中的 TextBlock 会显示反转文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9591913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com