Workarounds for WPF text Strokes (ii)

Source: Internet
Author: User

Since the day before the formatting text effect came out, today added text vertical and adjust the character spacing function. In addition, due to the last hasty, did not have time to do some of the features of the design support, this time also adjusted well.

Because I am relatively lazy, did not redo, the text vertical and character spacing is mainly through the new inheritance from the StackPanel Formatedtext class-by-character add Strokeablelabel do, The vertical row is the stackpanel.orientation to set, the character spacing mainly uses the strokeablelabel.margin.

For Strokeablelabel just added design-time support, others do not change, see http://blog.csdn.net/springberlin/article/details/45699625 for details

Formatedtext The following new attributes are added:

stretchsize: Character spacing

textorientation: Text typesetting

Below is

Xmal Configuration:

<window x:class= "Strokeablelabeltest.mainwindow" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/ Presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:wpflib=" Clr-namespace:blctclassli Brary. Wpflib;assembly=blctclasslibrary.wpflib "title=" MainWindow "height=" 422 "width=" 579 "> <grid showgridlines= "True" > <Grid.ColumnDefinitions> <columndefinition width= "Auto"/> <columnd            Efinition width= "*"/> </Grid.ColumnDefinitions> <stackpanel orientation= "Vertical" > <label margin= "content=" Below is Strokeablelabel class (relatively lightweight) "/> <wpflib:strokeablelabel text=" Test text Fil  L= "Yellow" stroke= "Black" strokethickness= "0.3" fontweight= "Bold" fontsize= "/> <wpflib:strokeablelabel" text= "Test text" fill= "Yellow" stroke= "Red" strokethickness= "0.7" fontweight= "Demibold" fontsize= "> <w" pflib:strokeablelabel.effect&Gt <dropshadoweffect color= "Black" blurradius= "renderingbias=" quality "direction=" 290 "shadowdepth=" 5 "Opacity=" 1 "/> </wpflib:StrokeableLabel.Effect> </wpflib:StrokeableLabel> < Wpflib:strokeablelabel text= "Test text" fill= "White" strokethickness= "2" fontweight= "Bold" fontsize= "> &lt" ;wpflib:strokeablelabel.stroke> <LinearGradientBrush> <lineargradien                            tbrush.gradientstops> <gradientstop color= "Blue" offset= "0.2"/> <gradientstop color= "Brown" offset= "0.3"/> <gradientstop color= "Powderblue" OFFSE t= "0.7"/> <gradientstop color= "Red" offset= "1"/> </lineargra Dientbrush.gradientstops> </LinearGradientBrush> </wpflib:strokeablelabel.st Roke> </wpflib:StrokeableLabel> <wpflib:strokeablelabel text= "Test text" stroke= "Red" strokethickness= "2" Fontwe ight= "Bold" fontsize= ">" <wpflib:StrokeableLabel.Fill> <imagebrush imageso Urce= "/strokeablelabeltest;component/images/20085385922474_2.jpg"/> </wpflib:strokeablelabel.fill&gt            ; </wpflib:StrokeableLabel> <wpflib:strokeablelabel fill= "Transparent" fontsize= "fontweight=" Light " Strokethickness= "8" text= "Test Text" > <wpflib:StrokeableLabel.Stroke> <imagebrus            H imagesource= "/strokeablelabeltest;component/images/05.jpg"/> </wpflib:StrokeableLabel.Stroke> </wpflib:StrokeableLabel> </StackPanel> <stackpanel grid.column= "1" orientation= "Ve Rtical "> <textblock margin=" "text=" the following is the Formatedtext class (you can make the text vertical on the basis of Strokeablelabel, you can control the spacing of characters) "Textwrapping= "Wrapwithoverflow"/> <wpflib:formatedtext stretchsize= "-5" textorientation= "Vertical" HorizontalAl            Ignment= "Center" text= "Test text" fill= "Yellow" stroke= "Black" strokethickness= "0.3" fontweight= "Bold" fontsize= "/>" <wpflib:formatedtext stretchsize= " -10" horizontalalignment= "Center" text= "Test text" fill= "Yellow" stroke= "Black" Str okethickness= "0.3" fontweight= "Bold" fontsize= "/> <wpflib:formatedtext stretchsize=" "Horizontalalig"                Nment= "Center" text= "Test text" fill= "Yellow" stroke= "Black" strokethickness= "0.3" fontweight= "Bold" fontsize= ">" <wpflib:FormatedText.Effect> <dropshadoweffect color= "Black" blurradius= "RENDERINGB"            ias= "Quality" direction= "290" shadowdepth= "5" opacity= "1"/> </wpflib:FormatedText.Effect> </wpflib:FormatedText> </StackPanel> </Grid></Window>


The library file only stick to the key code, the rest please refer to the source. The library file uses Strokeablelabel for layout to achieve horizontal/vertical and character spacing effects:

        private void CreateText (string newstr) {this.            Children.clear ();            if (newstr = = null) return; This.            Orientation = textorientation; for (int i = 0; i < newstr.length; i++) {if (I < newstr.length-1) ad                Dchar (Newstr[i], false);            else Addchar (Newstr[i], true); }}///<summary>///Add a character////</summary>//<param name= "C" ></ param> private void Addchar (char c, bool ignore) {Strokeablelabel label = new Strokeablelabel            (); Label.            Text = C + ""; Label. Fill = this.            Fill; Label. Stroke = this.            Stroke; Label. StrokeThickness = this.            StrokeThickness; Label. FontSize = this.            FontSize; Label. FontFamily = this.            FontFamily; Label. FontStyle = this.            FontStyle; Label. FontWeight = This.            FontWeight; Label. FontStretch = this.            FontStretch; if (!ignore) switch (Orientation) {case System.Windows.Controls.Orientat Ion. Horizontal:label.                        Margin = new Thickness (0, 0, stretchsize, 0);                    Break Case System.Windows.Controls.Orientation.Vertical:label.                        Margin = new Thickness (0, 0, 0, stretchsize);                Break } label.            VerticalAlignment = System.Windows.VerticalAlignment.Center; Label.            HorizontalAlignment = System.Windows.HorizontalAlignment.Left; This.        Children.add (label); }


Source:

http://download.csdn.net/detail/wblct/8708017


 

Workarounds for WPF text Strokes (ii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.