WPF- "LineSpacing" in a TextBlock - c#

I have a TextBlock I would like to pass a property of 'LineSpacing'. The thing with using "LineHeight" with LineStackingStrategy="BlockLineHeight" is that it also applies the LineHeight to the segment before the first line:
How can I manage to preserve said 'LineSpacing' without modifying the LineHeight before the first line?
One thing I though might work is to separate each line in a Paragraph of a FlowDocument, since the Paragraph has a property Spacing Before Line and Spacing After Line.
Any help would be truly appreciated. Thanks in advance.
ANSWER
It seems that you can use LineStackingStrategy="MaxHeight" to avoid having leading on the first line. (Check answers below for full details).
P.S. Thanks to Mitch for the revelation :D

It seems that you can use LineStackingStrategy="MaxHeight" to avoid having leading on the first line:
<TextBlock LineStackingStrategy="MaxHeight" TextWrapping="Wrap" LineHeight="50">Lorem...</TextBlock>
Produces

Related

Windows Phone 8 Font Binding

I'm really stumped on how to go about binding fonts to a textbox. I'd like for my user to be able to choose between 3-4 different fonts. I have something like this right now:
<TextBox x:Name="MyTextBox" AcceptsReturn="True" FontSize="20"
FontFamily="{Binding FontSelection}" />
But I have no clue how the c# should look, and I had no luck googling for it. What is the best way to do this? Do I have to create an observable collection? I've tried adding fonts to the Application.Resources, but it wouldn't let me.
Thanks for any answers!
This FontSelection property has to be single item. You could first try simple valid string (like 'Arial'), it could work. Another approach is FontFamily type as poined out by Romasz.
Also there are Converters available, quite easy to implement. http://channel9.msdn.com/Series/Windows-Phone-8-1-Development-for-Absolute-Beginners/Part-25-Advanced-Binding-with-Value-Converters With this you could save user font selection as simple number for example and convert it to appropriate type with Converter.

WPF blurry font in one control

I have the problem, that the font in my application is blurry. The curious thing is, that only one control (Grid with Columns and Rows) is blurry, the rest works perfect:
I have tried the following parameter, but that changed nothing:
RenderOptions.ClearTypeHint="Enabled"
TextOptions.TextFormattingMode="Display"
TextOptions.TextRenderingMode="ClearType"
SnapsToDevicePixels="True"
The same control (First is correct, second is blurry):
Maybe someone has an idea how to solve this problem, thank you!
ANSWER:
The problem was solved by using (Thank you Heena Patil):
RenderOptions.BitmapScalingMode="NearestNeighbor"
Try this using
RenderOptions.BitmapScalingMode and RenderOptions.EdgeMode="Aliased"
RenderOptions.BitmapScalingMode="NearestNeighbor" or RenderOptions.EdgeMode="Aliased"

How to Line Break or new line in XAML

I am having hard time to match Special characters set in XAML. I only on the following:
To represent a LineBreak in XAML hyperlink button:
use : > lineBreak <
But What do I use to represent a New Line or LineBreak In XAML hyperlink button??
Example : I want this one line mag : This is line one. This is line two
into this :
This is line one. This is line two.
it seems this \r\n is not working. This is line one \r\n
You've got options. For example;
<HyperlinkButton Content="Line One
Line Two"/>
or
<HyperlinkButton>
<HyperlinkButton.Content>
<TextBlock>
<Run Text="Line 1"/><LineBreak/><Run Text="Line 2"/>
</TextBlock>
</HyperlinkButton.Content>
</HyperlinkButton>
Hope this helps.
Addendum: You can do this stuff in basically anything. WPF, Silverlight, UWP, whatever. It's not WP specific.
You can use preserve. It includes all whitespace, so inputting the exact string you want would involve messing up your indentation, but this will work:
<HyperlinkButton xml:space="preserve">This is line one.
This is line two.</HyperlinkButton>

Finding the cause of Style problems

In a large WPF-project setting padding on buttons does not have any effect what so ever. No styles, templates, etc are set on the button, but still it won't use my padding.
<StackPanel>
<Button Padding="20, 20">Hello</Button>
</StackPanel>
I tried this in a brand new project and it works like a charm. Obviously there is some global style, template somewhere in the project causing this. Either somewhere in the xaml file, or in some resource file. As this project is rather hefty I going through everything is not feasable.
How to I debug this? Can I see what is overriding the padding?
I tried snooping around with Snoop 2.7.0, but it didn't really tell me much. Any hints on how to proceed with this type of error?
EDIT
I loked at the ValueSource for some properties:
Padding=Local
ContentTemplate=Default
Template=Style
What about the method DependencyPropertyHelper.GetValueSource?
http://msdn.microsoft.com/en-us/library/system.windows.dependencypropertyhelper.getvaluesource.aspx
There is a page on Dependency Property Value Precedence in the MSDN.
Why is it important? few people really know the order of precedence when it comes to dependency property values.
For example, did you know that whatever value you set in the CoerceValueCallback of a DP will overwrite any other set?
I'd suggest you go over that link and start from top (strongest set, will overwrite anything) to bottom (weakest set, will get overwritten by anything), there's a level in there where your value got set.
But hey, if you look at that list, you'll notice you're already in position 3! local value. So you only have 2 levels up: animation and value coercion ;)
I find your own answer might not be correct as well.
Whatever you put in your Button object will overwrite what's defined in the style.
I guess the reason that the padding you defined inside the button doesn't do anything is because, in your default style, the ContentPresenter is missing this,
<ContentPresenter Margin="{TemplateBinding Padding}"
The padding is the distance between the text and the border of the button, that is, the margin of this ContentPresenter.
this works for me:
<Button>
<Button.Content>
<TextBlock Padding="20" Text="Hello world!" />
</Button.Content>
</Button>
This particular problem was caused by a style defined in a resource included in the App.xaml.
The important lesson here is that styles without the x:Key attribute will affect all elements of the target type as described here.
Performing a solution wide wild card search on <Style*TargetType="*Button yielded a list of potential styles that would affect my button. I found one without the x:Key attribute, commented it out just to try and voila! The padding works.

WPF: how to set infinity symbol as content for a label?

I have a label. As the content I want to set the infinity symbol. How can I achieve that?
<Label Content="∞" ... />
FYI: XML Character Entities and XAML
Like this:
<Label Content="∞"/>
The infinity symbol is represented by the unicode character 221e. If you follow the link it shows fonts that support the character. It seems like most popular fonts do, including Arial, which I think is the default font for labels.
Somethig like this (might need to specify size of the image):
<Label>
<Label.Content>
<Image Source="URI to Image"/>
</Label.Content>
</Label>
Edit: Since you posted a picture i assumed you have an image, if you want the symbol as text say so.
See here: http://www.fileformat.info/info/unicode/char/221e/index.htm

Categories