I need to use a font family in my application. I added the following snippet in App.Resources
<FontFamily x:Key="SourceSanProFontFamily">Assets/Fonts/SourceSansPro-Regular.ttf#Source Sans Pro</FontFamily>
And i applied fontfamily to the textblock.
<TextBlock Text="Welcomeg!" FontFamily="{StaticResource SourceSanProFontFamily}"></TextBlock>
When application is not running,it is fine and i can see the change. But when I running the application it doest not take effect.
Why this happens? How to resolve this?
Our combined forces managed to solve the problem - after checking the working sample project it turend out that when the FontFamily is declared in other ResourceDictionaries additional / is needed:
<FontFamily x:Key="SourceSanProFontFamily">/Assets/Fonts/SourceSansPro-Regular.ttf#Source Sans Pro</FontFamily>
Related
This question already has answers here:
Using a custom font in WPF
(4 answers)
Closed 1 year ago.
I have a custom font that I add on my project and I make it work.
This is how it look like in the editor with the WPF code :
<TextBlock Style="{StaticResource ArabicFont1}" TextWrapping="Wrap" VerticalAlignment="Top" FontSize="30" HorizontalAlignment="Right">
<Run Text="{Binding text_arabe}"/>
</TextBlock>
Font displayed on the editor
But when I start the app, this is what font I have, with the exact same text :
Font when the app is started
So as you can see it's two different font, but in the editor, it show the right one and in the software the default one
So I don't really understand, can someone help me with this, please?
Thank you
If it can help- here is the app.xml
<Application.Resources>
<Style x:Key="ArabicFont1">
<Setter Property="TextElement.FontFamily"
Value="pack://application:,,,/fonts/#noorehidayat" />
</Style>
</Application.Resources>
You need to make sure that the font is installed on the executing system or the font is found in the execution folder of your application.
Please look at this example, maybe this will help you:
Use custom fonts in wpf c# applications
So I've googled all day trying to find an answer and have come up short. I've found stuff close and maybe even found a solution and just didn't realized it but I cant seem to get the Minimize, Maximize / Restore, and Close buttons to show up (be visible) on my windows 10 machine. No one but myself and another developer who just got new laptops have this issue. I've tried changing my windows theme around and I did get them to show up with I turned some high contrast setting on but no luck otherwise. Despite not being visible they are there and functional because I can click in the area and see the window min, max, restore, close.
We are using .Net 4.0 and a RibbonWindow with a custom theme (BureauBlue.xaml). I'd like to believe it may have something to do with that but I don't know anything about it or where to start unfortunately.
<r:RibbonWindow x:Class="Ztools.Main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:props="clr-namespace:Ztools.Properties"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
IsTabStop="False" Icon="/Ztools;component/ztools32.ico" Height="830" Width="1200" WindowStartupLocation="CenterScreen" WindowState="Normal"
Loaded="RibbonWindow_Loaded" Closing="RibbonWindow_Closing"
xmlns:my="clr-namespace:System;assembly=mscorlib" Title="Ztools 2.0" Name="mainRibbon" FontSize="14" SizeChanged="mainRibbon_SizeChanged" LocationChanged="mainRibbon_LocationChanged"
StateChanged="mainRibbon_StateChanged" Deactivated="mainRibbon_Deactivated" KeyUp="mainRibbon_KeyUp" Background="{x:Null}">
<r:RibbonWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Ztools;component/themes/bureaublue.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</r:RibbonWindow.Resources>
</r:RibbonWindow>
Another thing I noticed but haven't verified by pulling out my old laptop yet is I'm pretty sure the nice looking buttons showed up at design time as well and didn't look like this.
Bonus question/issue is sometimes when our computers go to sleep/hibernate go from docking station to no station (not sure which one or both) the theme bar will also randomly black out like this. If I could look at fixing this at the same time that would be great.
I did change it to a normal Window and was able to see all the buttons correctly but I guess I'd rather not go that route and know what the issue is and solve it.
Any thoughts ideas or suggestions are greatly appreciated.
Edit: So I don't think it has anything to do with the theme? I commented out everything having to do with the theme and they still don't show up... Not sure why I didn't take that simple step a long time ago.
So going to post this again that way anyone with the same or similar issue can at least have an option to fixing their issue... since for some reason it was deleted despite containing valuable information as an alternative solution to the problem.
For now I changed it from a RibbonWindow to a Window an gave my Ribbon a margin of 0,-22,0,0 so things line up and look decent as suggested by a number of other SO posts. The buttons show up now, but aren't the RibbonWindow style so is what it is.
<Window x:Class="Ztools.Main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:props="clr-namespace:Ztools.Properties"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
IsTabStop="False" Icon="/Ztools;component/ztools32.ico" Height="830" Width="1200" WindowStartupLocation="CenterScreen" WindowState="Normal"
Loaded="RibbonWindow_Loaded" Closing="RibbonWindow_Closing"
xmlns:my="clr-namespace:System;assembly=mscorlib" Title="Ztools 2.0" Name="mainRibbon" FontSize="14" SizeChanged="mainRibbon_SizeChanged" LocationChanged="mainRibbon_LocationChanged" StateChanged="mainRibbon_StateChanged" Deactivated="mainRibbon_Deactivated" KeyUp="mainRibbon_KeyUp">
<r:Ribbon Title="Ztools 2.0 (Scale Configuration Editor)" IsTabStop="False" Background="#FFE5E5E5" FontSize="12" FontFamily="Arial" Margin="0,-22,0,0">
</r:Ribbon>
</Window>
The ribbonwindow in version 5 has set WindowStyle="none" by default.
Maybe the WindowStyle is just set to None?
Try set it to "SingleBorderWindow" its original default in the base class.
I not only had the same issue but was able to replicate it in a new project and fix it through this solution although for you it will require moving to a more recent .net version.
The problem seems to stem from using RibbonControlsLibrary. It's is an outdated version of the ribbon controls. As of .net 4.5 Ribbon is native to the framework and by removing the reference you'll be able to use the included RibbonWindow.
Move to a .net version 4.5+ and remove this reference
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
and use
<RibbonWindow>
instead of
<r:RibbonWindow>
I am trying to have a label in my WPF-Window that has a special font that is probably not installed on all computers.
This is currently my xaml-code for the label:
<Label x:Name="ping" Content="00" FontFamily="pack://application:,,,/resources/#visitor" HorizontalAlignment="Left" Margin="165,10,0,0" VerticalAlignment="Top"/>
And here is my project hierarchy:
But why doesn't the font appear in the application/on the label?
Sorry to drag up an old thread, but I found the solution to this. While the font filename is visitor1, FontFamily doesn't look for this and instead looks for the font name. Open the font file and you'll see the name is actually "Visitor TT1 BRK". Use this in your code and it will work:
FontFamily="CustomFonts\#Visitor TT1 BRK"
When I use the WPF Extended Toolkit BusyIndicator in any other application, I have no problems. Using it in my current application, the text is cut off. I have been playing around with the properties on the BusyIndicator. Here is the xaml:
<xctk:BusyIndicator IsBusy="True" Panel.ZIndex="1000"/>
I wanted to post a picture so you could see what it looks like. The "Please Wait..." text is too low and the bar is laying on top of it. Has anyone experienced this before? I am stumped on what to do. I can't figure out how to change the height of the content inside the box, if that is even the issue.
Edit:
It currently displays as the following:
But I want it to display without the text being covered:
The designer displays it how I want it to display but the application, while running, displays it as shown in image one.
I think that your problem is that you have changed the default textblock size. But you can also fix with the BusyContentTemplate
For example I make the text bigger and red:
<xctk:BusyIndicator IsBusy="True" Panel.ZIndex="1000" >
<xctk:BusyIndicator.BusyContentTemplate>
<DataTemplate>
<TextBlock Foreground="Red" FontSize="15">Please Wait</TextBlock>
</DataTemplate>
</xctk:BusyIndicator.BusyContentTemplate>
</xctk:BusyIndicator>
You can also change the textblock for whatever you want.
I hope this can help you.
I discovered the issue. The underlying datatypes in the WPF Extended Toolkit's BusyIndicator is a grid. One of the grid's properties were being set in a global style file that I was unaware of...
I using a separate project for my styles a and i have some line of codes like this in it:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Style x:Key="NazaninFont" TargetType="Control">
<Setter Property="FontFamily" Value="pack://application:,,,/Extra/Fonts/#IRNazanin"/>
</Style>
......
</ResourceDictionary>
My another styles (like control effects and...) work well when i use my style key in the element like this:
Style="{ms:MyStyleRef ResourceKey=MyStyleKey}"
But When i use the following code in my Lable element
<Label Style="{ms:MyStyleRef ResourceKey=NazaninFont}" x:Name="LabelRemainingSec" Content="{Binding RemainingSec}"/>
I have:
In Design Time >> The FontFamily is set on IRNazanin on the properties panel but have not correct font view in the designer!
BUT
In Run Time >> The FontFamily is set on Tahoma (Window font)
Also i tested this way:
I added a style base on my font styles in the separate project, in top of my Window, like this:
<Style x:Key="NazaninFont" BasedOn="{ms:MyStyleRef ResourceKey=NazaninFont}" TargetType="Label"/>
Then i use it in my Lable normaly:
<Label Style="{StaticResource NazaninFont}" x:Name="LabelRemainingSec" Content="{Binding RemainingSec}"/>
Result is same as previous way:
In the Design Time in the FontFamily is on IRNazanin and have not correct font view in XAML designer! And in Run Time it is on Tahoma
What do you think about my problem? I think think my styles can not give the font path to the Label control correctly.
This may or may not be what you are after, but I'll take a guess that it is :p
You can define a FontFamily Resource in your resource dictionary, or where ever you want really. Take note of how I have defined it in Window.Resources.
I have included the physical font file in my project inside a folder called 'fonts' (no need for packing), and referenced it using the Font name: value. This is found by double clicking the font file (where it displays a whole heap of demo text and the option to install). You do not use the name of the file itself, you use the Font name: value when referencing. Also, don't forget the # at the start of any font reference! :)
Then, call it like you would any other resource for font family
Both the labels will be a different font. Please note that the font change won't be visible during design time unfortunately, only during runtime.
Working code as a demonstration:
<Window x:Class="Tinker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="400" Width="500">
<Window.Resources>
<FontFamily x:Key="MyFont">fonts/#Roboto Thin</FontFamily>
</Window.Resources>
<StackPanel VerticalAlignment="Top">
<Label FontSize="36" Content="Helloooooo World!"/>
<Label FontSize="36" FontFamily="{StaticResource MyFont}" Content="Helloooooo World!"/>
</StackPanel>
</Window>