RichTextBlock, Paragraph, Hyperlink... and globalization - xaml

In Windows Phone 8.1 you can use different languages useing the property "x:Uid" of an element, if I do
<textblock x:Uid="string1"/>
and in a resource file I write
string1.Text: sentence in english
then "sentence in english" "is written" in the Text property of the textblock. For buttons would be string1.Content.
But I have a problem, I am using RichTextBlock, with a Paragraph and Hyperlink inside, I can use x:Uid but... which property to use? They don't have Text or Content property, so... how can I globalizate that elements?
Thank you.

The Paragraph and Hyperlink are collections. The actual text comes from a Run somewhere inside, and the Run has a Text property. If you set the run explicitly instead of implicitly then you can add x:Uid to its Text property:
Xaml:
<Hyperlink>
<Run x:Uid="hlink" Text="http://microsoft.com" />
</Hyperlink>
Resources.resw:
<data name="hlink.Text" xml:space="preserve">
<value>http://stackoverflow.com</value>
</data>
The displayed Hyperlink will pull the stackoverflow URL from the resource file.

Related

Embedded font doesn't recognize bold

How can i reference a embbed font in my silverlight project, considering that there are multiple files for the same font?
I used the following tags in a Fonts.xaml file:
<FontFamily x:Key="MyFamily">../../Resources/Fonts/segoeui.ttf#Segoe UI</FontFamily>
In another file I have a tag to link this fontfamily to any TextBlock.
When I have a simple TextBlock it works fine:
<TextBlock Text="Simple" />
But when i want a bold text, it is not working;
<TextBlock Text="Simple" Font-Weight="Bold" />
I Know that the bold font is in another file (segoeuib.ttf), but since I refer to a specific file, and not the font name, its not finding. How can i refer to both file, without having to add FontFamily tag to all my TextBlock that needs to display Bold text?
PS: If I use the Font family name, without the file name, it will work, but if my user doesn't have the font in his/her computer it wont work.
I discovered how to do it, sharing in case someone has the same problems.
Instead of referring to the .ttf file, just put all font files in a zip and refer to the zip:
<FontFamily x:Key="MyFamily">../../Resources/Fonts/SegoeUI.zip#Segoe UI</FontFamily>

Custom Font in Windows Phone 8

I tried to add a custom font into my application. I need it for the page title. I copied the font to a folder named "Fonts" and changed the build action to Content. In the property panel the font shows up in the font list. But when i add the font the page title doesn't change. It changes a little bit but not like the font i'm using. The odd thing is when i double click on the page title the text gets highlighted in the textblock and then the highlighted text shows in the font i want. This is confusing. What should i do to correct this?
XAML for the page title
<TextBlock Text="page title" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" FontFamily="/AppName;component/Assets/Fonts/Dekers_Bold.ttf#Dekers_Bold" />
You have to add fonts as BlendEmbeddableFonts
Open your solution in blend, go to the font manager and in "Embedded Fonts", check your custom font.
Then create a resource called
<FontFamily
x:Key="CustomFont">/Wake Jake;component/Fonts/Fonts.zip#FontName</FontFamily>
and add it as
FontFamily="{StaticResource CustomFont}"
It will work that way.
Let me know if you need further help
If the font is located in your main WP8 project, you don't need to use the /AppName;component path. Also make sure the Dekers_Bold is actually name of the font, you should maybe try DekersBold or just Dekers:
FontFamily="/Assets/Fonts/Dekers_Bold.ttf#DekersBold"
If this is not working, try to add your font as resources first:
<FontFamily x:Key="Dekers">/Assets/Fonts/Dekers_Bold.ttf#DekersBold</FontFamily>
...
<TextBlock Text="page title" Margin="9,-7,0,0" FontFamily="{StaticResource Dekers}" />
Any Font works in windows 8, but after you add it to your project, right click on the font, choose properties and set "Build action" to "Content". Have a great day!
Unfortunately not all fonts work with Windows Phone 8. It tried your font (donwloaded from dafont) in a WP 7.1 project as described here and it works perfectly. Doing the same in a WP 8 project... the font won't load. So, you probably have to pick another font.

Text control that render html

Does anyone know a Windows Phone textbox control that binds to HTML property? I've used C1RichTextBox and it does the job but it's too damn slow! Please help.
The control from ComponentOne is the only one I'm aware of.
Where I've had to display HTML content in the past I've used one of the following two approaches.
Display the content in a WebBrowser control.
Manually parse the HTML and convert it into XAML controls.
The first option is appropriate when there is large amount of HTML to parse and when it is likely to vary greatly. (i.e. you can't be sure you'll only get a certain set of tags being used.)
If using the second option, be sure to consider using the HTML Agility Pack to help tidy up the HTML before parsing it.
A possible workaround is to put RichTextBox into a ScrollViewer to take advantage of the hardware accelerated control.
<ScrollViewer>
<c1:C1RichTextBox Height="1000" />
</ScrollViewer>

Loading a rtf file in a windows store app

I am trying to load a rtf file in a windows store app, however this file comes with a style and sometimes that style is applied and ohter times isn't. This behaviour is TOTALLY random (If I rerun the app over and over again sometimes the container I am using uses the style, other doesn't).
I am using a RichEditBox only because RichTextBlock doesn't support rtf files.
I have a RichEditBox in the MainPage.xaml
<Grid>
<RichEditBox
x:Name="InfoContentView"
VerticalAlignment="Stretch"
BorderThickness="0"
Background="{x:Null}"
Foreground="#FFFFFF"/>
</Grid>
And then I inject the rtf file like this:
this.InfoContentView.IsReadOnly = false;
this.InfoContentView.Document.SetText(Windows.UI.Text.TextSetOptions.FormatRtf,
textContent);
this.InfoContentView.IsReadOnly = true;
Textcontent is loaded from application package. I supose that works since I see the text perfectly, even links work fine.
I have tried to put the Document text before each execution to empty. Also, I have added a button to refresh the behaviour and it doesnt work in the first execution but then, after I press the button several times, it is consistent.
I only wish that the behaviour is consistent. I don't care if I have to format the file in the file or in the application.
The rtf file is quite simple and you can download the rtf file here.
Well, this is ackward. I don't know if this is a bug or if I shouldn't be doing this.
This grid was inside another grid that had Visibility = Collapsed. It turns out that if I had the Visiblity equals to collapsed and then I change it to visible it would have this random behaviour. I have hidden it using the opacity and then it works. Although with this solution I had to do some hacky stuff so I could get touches in that area when the opacity is set to 0.
I am not satisfied with my answer, but it might save someone else time. I will accept any answer that explains this behaviour.

Windows Store Apps: Change the icon of an AppBar Button?

I want to change the icon of an AppBar Button in my Windows Store app.
I found that the AppBar buttons have XAML markup that looks like this:
<Style x:Key="PicturesAppBarButtonStyle"
TargetType="ButtonBase"
BasedOn="{StaticResource AppBarButtonStyle}">
<Setter Property="AutomationProperties.AutomationId"
Value="PicturesAppBarButton"/>
<Setter Property="AutomationProperties.Name"
Value="Pictures"/>
<Setter Property="Content" Value=""/>
</Style>
What does the content value  mean? Is there any refernece to the built-in icons ?
Also how can I display a different icon of my own ?
The Content is the Unicode character number for the used font "Segoe UI Symbol" .
See a list of symbols in
LIST OF BUTTON SYMBOLS
You can use CharacterMap to pick icons other than defined in StandardStyles.xaml. The character map gives you the hex code which you can then use in button style. There are tonnes of symbols in Segoe UI Symbol.
In case of if you want to use Image or Path, then you have to re-edit some visual states in the style.
The hex value  is a symbol in the Segoe UI font. This is the symbol shown in the center of the button.
I've written a blog post on how to create your own app bar button that includes a reference of Segoe UI symbols you can use, along with their hex values.