Monospaced TextBlock using Segoe WP font - silverlight

I have a numerical value that ranges from 100-500 that changes every second or so. Because numerical characters for Segoe WP are variable widths, the text jumps when it changes.
Using the Segoe WP font in a XAML file; Is there a way to make numerical (or any) text render with monospaced (fixed width) characters?

A work around is to use the "Segoe UI" font family instead, which has monospaced numbers, and is reasonably similar.

Related

Access opentype glyph names from WPF

Is there a way to access opentype glyph names in Windows Presentation Foundation? I want to display a glyph on a canvas, but the glyph is a special glyph in a special font, so there is no standard codepoint (of course there IS a codepoint, but I don't want to remember it for dozens of special glyphs).
The font has names for each glyphs which I want to use (such as "custom.specialsign"). Is it possible to get the character by glyph name?

silverlight textbox with equal space between leters

I'm developing an application for a bank, and I need a textbox for entering the money, like
My Idea was to create a textbox that has as a background the image of the grid, and than I just set the text size such that there is only a character in each box. but writing iiiii(5 characters) is as long as wwww (4 characters). Can I set a font or a character spacing such hat i ensure that the characters writen in the textbox will appear in separate boxes.
Ps: there are other similar boxes for name, so I don't inpu only digits.
You could use monospace (fixed width) font, Courier for example. Or you could create custom control with TextBox for each character, but in this case you would have to implement big chunk of custom logic.
Using a Glyphs control, you can set indices for exact spacing of the characters of the UnicodeString property. Check this for details: http://msdn.microsoft.com/en-us/library/bb979862%28VS.95%29.aspx.
You can set the value for the UnicodeString in the code-behind or viewmodel if you are using MVVM.

Can you specify different font size for each fallback font?

When specifying a fallback font in Silverlight, is it possible to pair it with a font size?
The problem is that different fonts take different amount of space at a given font size. I'd like to be able to provide font size for each fallback font to make them more compatible in terms of space consumption.
As of Silverlight 4, the answer is No. This is a great idea, and you should push for it! (Go here to request it)
fallbackFontFamilyName value only helps Silverlight FIND a font, not use it.
Here are the docs for FontFamily and FontSource.
XAML allows you to specify PT, or PX as the measurement for every FontSize. However, Silverlight doesn't care, and defaults all font sizes to PX. It would be nice if you could give a specific size for each USE of a font.
+1 for WPF, -1 to consistency

How can we extract actual font family from a CompositeFontFamily applied to a run in WPF RichTextBox

A composite font family is a collection of FontFamilies. On applying the composite font to a run, appropriate font from its font-collection is applied depending on text.
How can we get which actual font is being used in a run on which a composite font has been applied?
EDIT2: Suppose I have a run
<Run Text="Some text with different unicode characters not available in applied FontFamily" FontFamily="Global User Interface"/>
Now if I check run.FontFamily it returns "Global User Interface", but actual font applied is one from the FontFamily collection of this composite font. So I want to find out which font it is?
EDIT1: One way I can think of is - to find it the way WPF applies a font. For each language, the composite font specifies a set of fonts corresponding to specified range of characters. So we can find each of the character in a run of text, then lookup the font corresponding to this character in the fontfamilymap for current language.
Is this the right way? Are there any cases where it may fail?
Is it the only way? Is there any API\straightforward way instead?
Thanks

Can I limit WPF TextBlock height to two lines?

I just received a requirement to display a length of text in a control. The control is of a particular width and will be up to 2 lines in height. If it renders longer than two lines it will just display "..." at the end of the string.
Is this possible with any of the stock standard WPF controls?
Thanks,
D.
Set the Height of the TextBlock to be high enough to fit two lines. Set the TextWrapping to Wrap and the TextTrimming to CharacterEllipsis or WordEllipsis.
For the default Segoe UI 12Pt font, I find this does it
<TextBlock TextWrapping="Wrap" Height="40" TextTrimming="CharacterEllipsis" />
You could probably do some code behind to work out the height it should be be for a particular font if you want.
That's not standard behavior that I've ever found, but again I've not looked for it.
One possibility is to use a monospace font in a TextArea control, and then if the string is greater than however many characters fit in the area, only display the right N characters with the ellipses

Resources