I'm facing a awkward problem. I can't set the FontStyle of a text. This is annoying me cause until now I'm not able to understand why the System. Drawing is missing, why I can't import her (At least I think I shouldn't).
The context is I'm in a silverlight application, setting the font color and style of a dynamic tree.
I'm using System.Windows.Media.SolidColorBrush to the Foreground, but I trying to set the FontStyle without success. And all google that I try answer the simple: 'use System.Drawing'
What I'm missing here?
You should not try to create a new FontStyle struct, but use the static properties of FontStyles: FontStyles.Italic or FontStyles.Normal.
Related
I have a project in UWP where I need to display the same text in a RichEditBox and in a RichTextBlock.
For some fonts (e.g. Courier), this is pretty ok and no big problems, but for other fonts (like Arial) the difference is pretty substantial.
Please note that I use exactly the same code, the only difference is just the Font.
Please find an MVCE that reproduces the issue here: https://github.com/vfailla/UWPRichEditBox
How can I setup the two elements to display the text in Arial in the very same visual way?
For some fonts (e.g. Courier), this is pretty ok and no big problems, but for other fonts (like Arial) the difference is pretty substantial. Please note that I use exactly the same code, the only difference is just the Font.
First of all, you will need to set the same CharacterSpacing of these two different controls:
m_richEditBox.CharacterSpacing = 100;
m_richTextBlock.CharacterSpacing = 100;
Then, you will need to set the same FontStretch of two controls, but here comes the issue:After a few tests I found textStretch doesn't work for RichEditBox/TextBox. And by default, the text inside look more like FontStretch.Condensed. So as a temporary workaround, you can set your RichTextBlock.FontStretch to FontStretch.Condensed:
m_richTextBlock.FontStretch = FontStretch.Condensed;
I'll consult through internal channel to report this issue, and I'll update this thread once I got any response.
I have a Infragistics UltraTextEditor (v.18.2): I set the font property to "Consolas", "10pts" both in the "Appearance" and in the "Font" sections of the control's properties.
The UltraTextEditor displays correctly (i.e. with my font properties) its content, but when I edit the content, font is set to 9pts, which seems to be it's default. I (and my users) would like the font to stay set at 10pts, of course. Is there something I am missing?
Thanks in advance to anyone who will help
The quick answer is that you can avoid this by doing one of two things:
Set the UltraTextBox property of AlwaysInEditMode = True
Set the UltraTextBox property of TextRemderingMode = GDI
The change in spacing (between edit and non-edit mode) is caused by the underlying .NET TextBox, which was created before GDI+. .NET uses GDI+ as it's native mechanism for drawing and the UltraTextBox uses GDI+ when displaying the UltraTextBox in non-edit mode. When entering edit mode, the drawing mechanism changes to the old GDI, which causes a difference in spacing.
Credit: Infragistics Community Forum
When settings the background color in the WMAppManifest like following example the phone themes color is still used.
The microsoft documentation points out it will only work if the color starts with #FF... http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207009(v=vs.105).aspx
Important Note:
If the BackgroundColor element's color value does not begin with #FF, such as #FF524742, your custom background color will not display and the default theme color will display instead.
<Tokens>
<PrimaryToken TokenID="WindowsPhoneApp" TaskName="_default">
<TemplateIconic>
<SmallImageURI IsRelative="true" IsResource="false">Assets\Tiles\IconicTileSmall.png</SmallImageURI>
<Count>0</Count>
<IconImageURI IsRelative="true" IsResource="false">Assets\Tiles\IconicTileMediumLarge.png</IconImageURI>
<Title>WindowsPhoneApp</Title>
<Message>
</Message>
<BackgroundColor>#FF016FAC</BackgroundColor>
<HasLarge>True</HasLarge>
<LargeContent1>
</LargeContent1>
<LargeContent2>
</LargeContent2>
<LargeContent3>
</LargeContent3>
<DeviceLockImageURI IsRelative="true" IsResource="false">
</DeviceLockImageURI>
</TemplateIconic>
</PrimaryToken>
</Tokens>
How to get this working? Is this a known bug?
Found the solution. The Microsoft documentation is lacking some information when setting this from the WMAppManifest.
As the documentation reads when setting the backgroundcolor in xml you should always start your color with #FF.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207009(v=vs.105).aspx
However you should do this when you use an xml file as your tile configuration you should NOT do this in the AppManifest. In the AppManifest just specify the color without the Alpha channel, so just #RRGGBB and make sure there are no spaces arround or new lines.
Following should be on one line exactly like this.
<BackgroundColor>#016FAC</BackgroundColor>
When you try to do it like this it will not work:
<BackgroundColor>
#016FAC
</BackgroundColor>
Microsoft if you read this please update the docs. It will save a lot of people a lot of researching.
Background property does not work when it declared in the manifest, but will work if you'll set it from the code.
I have made a control in silverlight that has a SolidColorBrush property. In XAML, you can set this to be preexisting Colors such as Black, Yellow, White, etc. I assume there is a TypeConverter that takes the string "Black" and converts it to a Color object and creates a new SolidColorBrush based on this object. I want this functionality to remain, but with the added capability to also accept hex strings to set the color. I would need a TypeConverter for this, correct? Is there a way I can extend from the current one so that I can still pass in color names?
XAML already accepts hex. Eg:
Background="#FF9D661C"
Having the VS Properties pane open while on a XAML element helps indicate possibilities thats aren't necessarily obvious via intelisence (Eg setting Background as hex or a gradiant brush).
As #Ricibob said, the existing converter alreadys works how you want it to. In addition, it looks like all of the built in TypeConverters are sealed, so you can't inherit from them (although there's nothing keeping you from using composition to solve the problem).
I'm working on a C# WPF project that has the Roboto and Roboto Thin fonts embedded. They font files are in /Resources/Fonts and their build actions are set to 'Resource'. In my App.xaml, I declare the resources:
<FontFamily x:Key="Roboto">/Resources/Fonts/#Roboto</FontFamily>
<FontFamily x:Key="RobotoThin">/Resources/Fonts/#Roboto Thin</FontFamily>
The Roboto font works properly (as do some other embedded fonts), but Roboto Thin doesn't work. I've tried '.../Roboto-Thin.ttf', 'Roboto-Thin', 'Roboto_Thin' and the FontWeight property on the label/textblock but nothing works. When I try to use Roboto Thin on a UIElement, it doesn't seem to recognize it and it falls back to the default font (probably Segoe UI).
What am I doing wrong?
-- edit --
I just tried Roboto Light, but that doesn't work either. It would seem that only the regular fonts work but variations don't.
Not sure if its what you're looking for, but what works for me is the following:
<FontFamily x:Key="robotoRegularFont">/resources/Roboto-Regular.ttf#Roboto</FontFamily>
<FontFamily x:Key="robotoThinFont">/resources/Roboto-Thin.ttf#Roboto Thin</FontFamily>