Page 1 of 1

LocalFontProvider is affected by LocalXamlProvider ?

Posted: 20 Sep 2017, 09:34
by nikobarli
I have the following directory setup:
<root>/Xaml/*.xaml
<root>/Font/*.ttf
and a xaml file which load a font "Fonts/#Arial Unicode MS", as follows.
<UserControl x:Class="NoesisTutorial.Tutorial"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:NoesisTutorial"
             FontFamily="Fonts/#Arial Unicode MS" 
             FontSize="20"
             mc:Ignorable="d" 
             d:DesignHeight="800" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="NoesisStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <StackPanel>
    </StackPanel>
</UserControl>
If I set my LocalXamlProvider to the directory <root>/Xaml and my LocalFontProvider to directory <root>, everything works fine.

Then I changed the directory of my LocalXamlProvider to <root>, and adjust my code to call LoadXaml with filename prefixed with "Xaml" (e.g. "Xaml/Test.xaml" instead of "Test.xaml"). The Xaml can be loaded correctly, but it fails to load the font.

Is it intended behavior ?

Re: LocalFontProvider is affected by LocalXamlProvider ?

Posted: 22 Sep 2017, 13:06
by jsantos
Then I changed the directory of my LocalXamlProvider to <root>, and adjust my code to call LoadXaml with filename prefixed with "Xaml" (e.g. "Xaml/Test.xaml" instead of "Test.xaml"). The Xaml can be loaded correctly, but it fails to load the font.

Is it intended behavior ?
Yes, because this
FontFamily="Fonts/#Arial Unicode MS"
is an URI relative to the XAML. So, it is trying to load the font from Xaml/Fonts/...

You can avoid this behavior by using a non-relative URI:
FontFamily="/Fonts/#Arial Unicode MS"

Re: LocalFontProvider is affected by LocalXamlProvider ?

Posted: 25 Sep 2017, 02:22
by nikobarli
Ah, my bad. Didn't realize that the path can be absolute or relative. Thanks.

Re: LocalFontProvider is affected by LocalXamlProvider ?

Posted: 26 Sep 2017, 21:03
by jsantos
You welcome. Marking this as solved.