2016-03-28 22 views
2

WPF Arapça Modunda (FlowDirection = "RightToLeft") kullanın. i verdiğindeTextBlock Stili her zaman Run Tag

yukarıda çözecektir ardından kod % 24.7-

olarak bu yazdırır -24,7% gibi bir takım sorunlar söz etti.

<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> 

Şimdi benim metin Bloklar İçindekiler'i tüm <run><run> etiketi koymak istiyorum, ben bunu başarabilirsiniz nasıl Yani ben kodunda benim TextBlocks tüm değiştirmek zorunda değilsiniz.

Bunu bir Stil oluşturarak nasıl yaparsınız?

not: i uygulamadaki tüm textblockes düzenleyemediğinizden ben TextAlign = Sağ çözüme gidemez

+0

:

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()); } } } 

Ve tüm metin blokları için bu özelliği ayarlamak için kaynaklar

söyledi. –

+0

@VibeeshanRC TextBlock'larınızı sadece negatif sayılarınız var mı? Değilse, ve biz tüm tersine çevirir (ve TextBlocks) Arapça tersine değil mi? Bu kötü bir yan etki, değil mi? – Taterhead

cevap

1

Ben senin yaklaşım gibi ama bilmiyorum diyemeyiz Arapça gotchas ve senin durumun, bu yüzden bunu tartışmayacağım. Eklediğiniz özellikleri (veya harmanlama davranışlarını) kullanarak istediğinizi elde edebilirsiniz. Şunun gibi: Muhtemelen kullanmak sonra bunun içine çalıştırmak etiketleri ile bir textblock bir usercontrol oluşturmak ve istediğiniz

<Window.Resources> 
    <Style TargetType="TextBlock"> 
     <Setter Property="local:StrangeAttachedProperty.AddRunByDefault" Value="True" /> 
    </Style> 
    <Style TargetType="Run"> 
     <Setter Property="FlowDirection" Value="LeftToRight" /> 
    </Style> 
</Window.Resources>