2016-03-28 12 views
2

を使用するスタイル。TextBlockスタイルWPFアラビア語モード(FlowDirection = "RightToLeft")で常に実行タグ

私は-24.7%のように番号を与えるとき、それはコードは、上記の問題を修正します後%24.7-

としてこれを印刷します。

<Window.Resources> 

    <Style TargetType="Run"> 
     <Setter Property="FlowDirection" Value="LeftToRight" /> 
    </Style>  

</Window.Resources> 

<Grid FlowDirection="RightToLeft" > 
    <Grid HorizontalAlignment="Left" Margin="114,127,0,0" VerticalAlignment="Top" Width="279" Height="97"> 
     <TextBlock x:Name="textBlock" Text="-24.7%" ><Run></Run></TextBlock> 
    </Grid> 
</Grid> 

は、今私はどのように私はこれを達成することができ、私のテキストブロックの内容のすべてに<run><run>タグを入れたいので、私はコードで私のテキストブロックのすべてを交換する必要はありません。

スタイルを作成することでこれを行う方法... ??

注:私は、アプリケーション内のすべてのtextblockesを編集することはできませんように私はTextAlign =右の溶液に行くことができない

+0

あなたは、おそらくそれの内部で実行タグでテキストブロックでユーザーコントロールを作成し、使用したいですそれ。 –

+0

@VibeeshanRCあなたのTextBlocksには負の数値しかありませんか?そうでない場合は、すべての実行(およびTextBlocks)を取り消してアラビア語を逆転させることはありませんか?それは悪い副作用です、いいえ? – Taterhead

答えて

1

私はあなたのアプローチを好むが、私は知らないと言うことはできませんアラビア語の問題とあなたの状況は、それについて議論しません。アタッチされたプロパティ(またはブレンド動作)を使用して、あなたが望むものを達成することができます。

public static class StrangeAttachedProperty { 
    public static bool GetAddRunByDefault(DependencyObject obj) { 
     return (bool) obj.GetValue(AddRunByDefaultProperty); 
    } 

    public static void SetAddRunByDefault(DependencyObject obj, bool value) { 
     obj.SetValue(AddRunByDefaultProperty, value); 
    } 

    public static readonly DependencyProperty AddRunByDefaultProperty = 
     DependencyProperty.RegisterAttached("AddRunByDefault", typeof (bool), typeof (StrangeAttachedProperty), new PropertyMetadata(AddRunByDefaultChanged)); 

    private static void AddRunByDefaultChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { 
     var element = d as TextBlock; 
     if (element != null) { 
      // here is the main point - you can do whatever with your textblock here 
      // for example you can check some conditions and not add runs in some cases 
      element.Inlines.Add(new Run()); 
     } 
    } 
} 

そして、すべてのテキストブロックのために、このプロパティを設定し、あなたの資源が:このよう

<Window.Resources> 
    <Style TargetType="TextBlock"> 
     <Setter Property="local:StrangeAttachedProperty.AddRunByDefault" Value="True" /> 
    </Style> 
    <Style TargetType="Run"> 
     <Setter Property="FlowDirection" Value="LeftToRight" /> 
    </Style> 
</Window.Resources> 
関連する問題