Bruno Ramirez
Bruno Ramirez

Reputation: 46

The WPF resource font is not updated

I have added a new font "Renner.ttf" into resources of the project. Then I tried to use it with a dynamic resource using <Windows.Resources/>. In the design view it seems to be ok:

Design view:

This is the actual font that I want so, then I build and run the project and that what I got:

Build:

This isn't the font I want, so what im doing wrong?

This is the code:

XAML:

<Window x:Class="MyProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:MyProject"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">

<Window.Resources>
    <Style x:Key="Renner">
        <Setter Property="TextElement.FontFamily" Value="/MyProject;component/Resources/#Renner"/>
    </Style>
</Window.Resources>

<Grid>
    <TextBlock x:Name="lblTitle" Style="{DynamicResource Renner}" FontSize="72">
        Reportes
    </TextBlock>

    <Button Width="150" Height="50" Click="Button_Click">
        <TextBlock Style="{DynamicResource Renner}" FontSize="20">
            Open New
        </TextBlock>
    </Button>

</Grid>

I have tried so far (without any luck):

  1. Clean the project and rebuild it.
  2. use it without the resource. <TextBlock FontSize="72" FontFamily="/MyProject;component/Resources/#Renner">Reportes</TextBlock>
  3. Install the Font and use it without the local resource like any other font.
  4. Delete the resource and re-added.

Upvotes: 1

Views: 592

Answers (1)

Andrew Cahill
Andrew Cahill

Reputation: 461

You will probably want to see BuildAction to Resource if you have not done so already.

Here is an MSDN article for reference: https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-3.5/ms753303(v=vs.90)

Upvotes: 2

Related Questions