Silverlight custom Font not working at runtime - silverlight

I have a Silverlight 4 Application that I run using Visual Studio 2012 Web Express. I added a CustomFont.zip in the Fonts folder of my project. the file is marked as "Resource".
When I use the font, in a TextBlock for example, I can see it in the Visual Studio XAML designer. But when I run the application it uses de default standard font.
Here's an example of my TextBlock
<TextBlock FontFamily="/Fonts/CustomFont.zip#MyFontName" >Hello World</TextBlock>
I have tried with embedded Zip like the example above. I also tried the font directly (without zip). Tried with TTF and OTF Font. Always same result I can see it at design time but not at runtime.
Thanks

I'm sure you have this working by now but I had the same problem. I got it to work by formatting my FontFamily string like below and you definitely don't want the file to be in a zip file. I have my font in a project folder I created called "Fonts".
<TextBlock FontFamily="./Fonts/MyFontName.ttf#MyFontName" >Hello World</TextBlock>

I also had same problem and I solved like below. I had to go through a lot of forums including this but none works. But some forum asked me to forcibly load font before I come to point of my interest.
In my TextBlockStyles.xaml resource dictionary I created a styke
<Style x:Key="RadWindowTitleTextStyle"
TargetType="TextBlock">
<Setter Property="Foreground"
Value="#FFB9D449" />
<Setter Property="FontSize"
Value="18.667" />
<Setter Property="FontFamily"
Value="/sampleawebsite.application;component/Assets/Fonts/UBSHead.ttf#UBSHeadline" />
</Style>
In my MainPage, I just gave below to load my font
<TextBlock Text="Do not display Font load purpose only"
Width="1"
Height="1"
Style="{StaticResource RadWindowTitleTextStyle}"
Foreground="Transparent" />
Below is my point of interest in one of my ChildWindow popup styles resource dictionary called RadWindowStyles.xaml
<TextBlock Text="{TemplateBinding Title}"
Style="{StaticResource RadWindowTitleTextStyle}" />

Related

WPF toolkit charting : Customize DataPoint ToolTip

I would like to add a tooltip over the datapoint of a lineseries that shows both the X and Y values (independent and dependent values), rather than just the dependent value that appears by default. I am aware this is the same question as was written in this ticket - WPF toolkit charting : Customize datapoint label
However, I can't get the answer to work. There is a link to more detail that appears to be outdated.
My line series:
<DVC:Chart.Series>
<!--Have several lineseries that look like this, connected to a styling vm. Can add ToolTip=...-->
<VM:LineSeries x:Name="something"
Title="something"
DependentValuePath="Value"
IndependentValuePath="Key"
ItemsSource="{Binding something}"
DataPointStyle="{StaticResource DataPointBlue}"
>
</VM:LineSeries>
</DVC:Chart.Series>
My datapoints are styled here, but adding a setter property with any tooltip doesn't make a difference:
<UserControl.Resources>
<Style x:Key="DataPointBlue" TargetType="{x:Type DVC:DataPoint}">
<Setter Property="Background" Value="Blue"/>
</Style>
</UserControl.Resources>
I've tried adding this line of code from the above linked ticket in several places in a variety of ways, and I've tried using Binding in various ways, but nothing has hit the mark.
<ToolTipService.ToolTip>
<StackPanel Margin="2,2,2,2">
<ContentControl Content="{TemplateBinding IndependentValue}" />
<ContentControl Content="{TemplateBinding DependentValue}" />
</StackPanel>
</ToolTipService.ToolTip>
This has been a lot of trial and error that hasn't been making progress.

WPF Font Awesome not working with Caliburn.Micro?

With caliburn.micro I can't access to any third-party fonts in my folder in my WPF Solution, and I was able to ensure the following:
Build Action is set to Resources
Font family = "./Font/#FontAwesome"
And I still cannot retrieve icons from Font Awesome.
The XAML code from my button:
<Button Name="MailButton"
Grid.Row="1" Grid.Column="2"
Width="60" Height="60"
Content=""
FontSize="30"
Foreground="White"
BorderThickness="0"
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
BorderBrush="{x:Null}"
FontFamily="./Font/#FontAwesome"
Background="#FF085078"/>
In my second project without using the Caliburn font, it worked, even when I tried to access it in the same way as I did in my first project. What can I do more to make this font working? What properties of my project should I check first?
You need to delete the leading period (.) from the font family path, then you can access your font. Example:
FontFamily = "/Font/#FontAwesome"

How to add a color to the header of a Telerik groupbox?

How can I add a color to the header of a telerik groupbox?
<StackPanel Orientation="Vertical">
<telerik:GroupBox Header="Demo">
<StackPanel Orientation="Vertical">
There are some built-in themes that you can apply directly to your GroupBox control. They provide some basic styling options and you may find the one that suits your need the most.
Built-in Themes: http://docs.telerik.com/devtools/winforms/panels-and-labels/groupbox/themes
But, in case you really don't want to use the built-in themes and only wish to customize the UI, then you should be looking at Telerik Presentation Framework (TPF) and design and implement your own GroupBox control.
Change the GroupBox header color
((FillPrimitive)this.radGroupBox1.GroupBoxElement.Children[1].Children[0]).BackColor = Color.Red;
((FillPrimitive)this.radGroupBox1.GroupBoxElement.Children[1].Children[0]).BackColor2 = Color.Yellow;
((FillPrimitive)this.radGroupBox1.GroupBoxElement.Children[1].Children[0]).GradientStyle = Telerik.WinControls.Gradien
More details on TPF here:
http://docs.telerik.com/devtools/winforms/panels-and-labels/groupbox/advanced/tpf-structure
As WoodKiddy mentioned earlier it would be advisable to use the c# version - setting the color programmatically.
It would seem that the telerik team themselves are suggesting the same here:
This question seems similiar to yours
I'm not really used to the xaml structure and again the dev team suggests using the c# approach. But this might do the work with some luck:
<Style x:Key="MyGroupBoxStyle" TargetType="{x:Type GroupBox}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="Black" FontWeight="Bold"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Good luck!

Cannot see FontAwesome Icons on Parent Window

Summary -- I cannot see FontAwesome icons in the designer when looking at my MainWindow.xaml view that includes a control that has the FontAwesome icons in it.
We are using Visual Studio 2012 to develop a WPF application using Simple MVVM. In our application, we use FontAwesome for most of our icons. I created a resources library that has a reference to FontAwesome (AppStyles.xaml).
Here is an excerpt from my AppStyles.xaml file that references FontAwesome.
<Style x:Key="FontAwesome" TargetType="Control">
<Setter Property="FontFamily" Value="/Fonts/#FontAwesome" />
</Style>
I have created a HeaderView.xaml view that shows a toolbar of options the user can select from. Example of one of the buttons the user can click is below.
<Button Command="{Binding ShowStartScreenAction}">
<Button.Template>
<ControlTemplate>
<StackPanel Orientation="Horizontal" Margin="0">
<Label Content="" Style="{StaticResource FontAwesomeLabel}" />
<Label Content="Home" Style="{StaticResource ButtonLabel}" />
</StackPanel>
</ControlTemplate>
</Button.Template>
</Button>
On the HeaderView.xaml view, the FontAwesome icons show up correctly (). A house in this case.
In my MainWindow.xaml view, I have the HeaderView.xaml view added as a control.
<ctrls:HeaderView Grid.Row="0" Grid.ColumnSpan="2" />
The problem I am having is that the FontAwesome does not show up correctly on MainWindow when I view it in the Designer, so I cannot see how the HeaderView.xaml and all my other controls look together inside MainWindow.
Here is my reference in MainWindow.xaml to my resources library where the FontAwesome reference is.
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources;component/Styles/AppStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
The application runs fine, but it would be nice to be able to see what I have in the designer without having to run the application to see it every time. Can someone help?

WPF - Add Custom Font

I'm trying to add a custom font as a resource in my application.
I have a "CustomFont" directory in the application and all the fonts inside of it are set to "Resource"
<Window.Resources>
<Style x:Key="Gotham-XLight">
<Setter Property="TextElement.FontFamily"
Value="/CustomFonts;Component/#Gotham-XLight" />
</Style>
</Window.Resources>
And then on my TextBlock I have this: (inside a grid)
<TextBlock x:Name="TimeTextBlock" Style="{DynamicResource Gotham-XLight}"
TextAlignment="Center" FontSize="25" FontWeight="Bold"
Foreground="White" Text="TextBlockTimer"
Margin="105,242.974,0,226.975" HorizontalAlignment="Left"
Width="221.919" />
But I'm not seeing my font as people say. Am I doing something wrong?
You may want to check the name of the font, you need to specify the name of the font not the name of the file.
Double click on the font file and it should show a "Font name:" that's what you want to make sure is specified in your style.
Try this
<Window.Resources>
<Style x:Key="Gotham-XLight">
<Setter Property="TextElement.FontFamily" Value="CustomFonts/#Gotham-XLight" />
</Style>
</Window.Resources>
Also, if you are not planning on changing the style at runtime {StaticResource Gotham-XLight} will be much more performant.
In xaml I did it like this:
<Button Grid.Column="1" Grid.RowSpan="2" Name="start" Margin="5" Click="start_Click">
<TextBlock Name="test" FontFamily="pack://application:,,,/Y_Yoga;Component/Resources/#FontAwesome"></TextBlock>
</Button>
However, I don't know if #FontAwesome is font's embedded name or is it the result that I renamed the .ttf file.
Hope to be helpful!
Late reply but worth mentioning. To add a custom font that will apply globally in your window you could add this in your csproj file to include the fonts from the Fonts folder of your project as resources.
<ItemGroup>
<Resource Include="Fonts\*.ttf" />
</ItemGroup>
Then in your window XAML you can specify the FontFamily in the Window part:
<Window x:Class="Namespace.MainWindow"
...
FontFamily="/Fonts/#[FONT NAME]"
Title="">
<Grid>
...
</Grid>
</Window>
I hope this could help somebody, as I spent some time to figure it out.

Resources