Solution to WPF text stroke (2)-supports vertical bar and Character spacing adjustment, and wpf stroke

Source: Internet
Author: User

Solution to WPF text stroke (2)-supports vertical bar and Character spacing adjustment, and wpf stroke

After the text is formatted the day before yesterday, the text vertical bars and Character spacing adjustment functions are added today. In addition, due to the last rush, it was not time to design some functions, and this time it was adjusted.

Because I am too lazy and haven't done it again, the vertical bar of text and the spacing between characters are mainly created by adding StrokeableLabel TO THE FormatedText class inherited from StackPanel, while the vertical bar uses StackPanel. orientation. StrokeableLabel is mainly used for Character spacing. margin.

For StrokeableLabel, only support at design time is added and others are not changed. If you are not familiar with StrokeableLabel, see the http://blog.csdn.net/springberlin/article/details/45699625.

FormatedText has the following new attributes:

StretchSize: Character Spacing

TextOrientation: Text Layout

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: BLCTClassLibrary. wpfLib; assembly = BLCTClassLibrary. wpfLib "Title =" MainWindow "Height =" 422 "Width =" 579 "> <Grid ShowGridLines =" True "> <Grid. columnDefinitions> <ColumnDefinition Width = "auto"/> <ColumnDefinition Width = "*"/> </Grid. columnDefinitions> <StackPanel Orientation = "Vertical"> <Label Margin = "10" Content = "The following is the StrokeableLabel class (relatively lightweight)"/> <wpflib: strokeableLabel Text = "test Text" Fill = "Yellow" Stroke = "Black" StrokeThickness = "0.3" FontWeight = "Bold" FontSize = "50"/> <wpflib: strokeableLabel Text = "test Text" Fill = "Yellow" Stroke = "Red" StrokeThickness = "0.7" FontWeight = "DemiBold" FontSize = "50"> <wpflib: StrokeableLabel. effect> <DropShadowEffect Color = "Black" BlurRadius = "15" 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 = "50"> <wpflib: StrokeableLabel. stroke> <LinearGradientBrush. gradientStops> <GradientStop Color = "Blue" Offset = "0.2"/> <GradientStop Color = "Brown" Offset = "0.3"/> <GradientStop Color = "PowderBlue" Offset =" 0.7 "/> <GradientStop Color =" Red "Offset =" 1 "/> </LinearGradientBrush. gradientStops> </LinearGradientBrush> </wpflib: StrokeableLabel. stroke> </wpflib: StrokeableLabel> <wpflib: strokeableLabel Text = "test Text" Stroke = "red" StrokeThickness = "2" FontWeight = "Bold" FontSize = "50"> <wpflib: StrokeableLabel. fill> <ImageBrush ImageSource = "/StrokeableLabelTest; component/Images/2008520.922474_2.jpg"/> </wpflib: StrokeableLabel. fill> </wpflib: StrokeableLabel> <wpflib: strokeableLabel Fill = "Transparent" FontSize = "50" FontWeight = "Light" StrokeThickness = "8" Text = "test Text"> <wpflib: StrokeableLabel. stroke> <ImageBrush ImageSource = "/StrokeableLabelTest; component/Images/05.jpg"/> </wpflib: StrokeableLabel. stroke> </wpflib: StrokeableLabel> </StackPanel> <StackPanel Grid. column = "1" Orientation = "Vertical"> <TextBlock Margin = "10" Text = "The following is the FormatedText class (based on StrokeableLabel, the Text can be vertically arranged to control the Character spacing) "TextWrapping =" WrapWithOverflow "/> <wpflib: formatedText StretchSize = "-5" TextOrientation = "Vertical" HorizontalAlignment = "Center" Text = "test Text" Fill = "Yellow" Stroke = "Black" StrokeThickness = "0.3" FontWeight = ""Bold" FontSize = "50"/> <wpflib: formatedText StretchSize = "-10" HorizontalAlignment = "Center" Text = "test Text" Fill = "Yellow" Stroke = "Black" StrokeThickness = "0.3" FontWeight = "Bold" FontSize = "50"/> <wpflib: formatedText StretchSize = "20" HorizontalAlignment = "Center" Text = "test Text" Fill = "Yellow" Stroke = "Black" StrokeThickness = "0.3" FontWeight = "Bold" FontSize =" 50 "> <wpflib: formatedText. effect> <DropShadowEffect Color = "Black" BlurRadius = "15" RenderingBias = "Quality" Direction = "290" ShadowDepth = "5" Opacity = "1"/> </wpflib: formatedText. effect> </wpflib: FormatedText> </StackPanel> </Grid> </Window>


Only key code is attached to the library file. For more information, see source code. StrokeableLabel is used in the library file for layout to achieve horizontal/vertical layout and Character Spacing effect:

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) addChar (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 S TrokeableLabel (); 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. orientation. 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 code:

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


ZookeeperWhen there are already too many other users

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.