bzhkl
Topic Author
Posts: 4
Joined: 26 Jun 2020, 10:13

I write a hello world , and found StaticResource not work, why

09 Jul 2020, 14:06

https://github.com/iomeone/gui/blob/760 ... w.xaml#L24

<CheckBox Content="abc1234" FontFamily="{StaticResource FontAwesome}"/>
<CheckBox Content="abc1234" FontFamily="FontAwesome"/>
these two line both work in c# project ,
but only the second works in c++ project . the first one can not set the fontfamily successfully, why?
I place the font in the fonts fold and write a Fonts.xaml in the Styles folder.
then in App.xaml
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Fonts.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
platform: win10 x64 vs2015
Last edited by bzhkl on 09 Jul 2020, 14:20, edited 1 time in total.
 
User avatar
sfernandez
Site Admin
Posts: 1881
Joined: 22 Dec 2011, 19:20

Re: I write a hello world , and found StaticResource not work, why

09 Jul 2020, 14:19

A StaticResource is a reference to a previously defined resource, inside Application.Resources, or the Resources of any element up in the tree.

So the following should work if you have FontAwesome installed in your operating system:
<StackPanel Height="100" Width="100">
  <StackPanel.Resources>
    <FontFamily x:Key="FontAwesome">FontAwesome</FontFamily>
  </StackPanel.Resources>
  <CheckBox Content="abc1234" FontFamily="{StaticResource FontAwesome}"/>
  <CheckBox Content="abc1234" FontFamily="FontAwesome"/>
</StackPanel>
these two line both work in c# project
Do you mean a Noesis C# project, or a Blend WPF project?
but only the second works in c++ project . the first one can not set the fontfamily successfully, why?
Maybe you defined FontAwesome resource in the application resources and you forgot to call Noesis::GUI::SetApplicationResources().
 
bzhkl
Topic Author
Posts: 4
Joined: 26 Jun 2020, 10:13

Re: I write a hello world , and found StaticResource not work, why

09 Jul 2020, 14:25

Do you mean a Noesis C# project, or a Blend WPF project?
Blend WPF project works.
<StackPanel.Resources>
<FontFamily x:Key="FontAwesome">FontAwesome</FontFamily>
</StackPanel.Resources>
I add this , then c++ project work! I don't need to have FontAwesome installed in my operating system.

It seems if I write
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/Fonts.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
in App.xaml, it will not take effect. Why , I want to set up my resourse in my styles folder and include them in App.xaml.
Can I do it like I did in blender wpf?
The blender wpf project is here https://github.com/iomeone/gui/blob/mas ... end.csproj , just In the next Data folder.
 
bzhkl
Topic Author
Posts: 4
Joined: 26 Jun 2020, 10:13

Re: I write a hello world , and found StaticResource not work, why

09 Jul 2020, 15:26

any Help?
 
bzhkl
Topic Author
Posts: 4
Joined: 26 Jun 2020, 10:13

Re: I write a hello world , and found StaticResource not work, why

10 Jul 2020, 04:49

In c++ project , you just write
<CheckBox Content="&#xf110;" FontFamily="./#FontAwesome"/>
then it worked. Do not need to declare Font resource anywhere.

I think because We already have compiled the font file in to the .h file. It's already in the EXE file , so just ./#FontAwesome will work.
 
User avatar
sfernandez
Site Admin
Posts: 1881
Joined: 22 Dec 2011, 19:20

Re: I write a hello world , and found StaticResource not work, why

10 Jul 2020, 11:11

I add this , then c++ project work! I don't need to have FontAwesome installed in my operating system.
As explained in our Text tutorial, if you don't use the # uri syntax, then fonts refer to system fonts, instead of local/application fonts. In your case, if FontAwesome is not installed in the system, you are seeing text because it is probably using fallback fonts (I guess you called NoesisApp::SetThemeProviders(), right?).
In App.xaml, it will not take effect. Why , I want to set up my resourse in my styles folder and include them in App.xaml.
Can I do it like I did in blender wpf?
If you are not using our application framework, and just following the integration tutorial, App.xaml file is not used, but you can have all your application resources defined or merged into a ResourceDictionary that you can then use to call: Noesis::GUI::LoadApplicationResources("Styles/AppResources.xaml");
I think because We already have compiled the font file in to the .h file. It's already in the EXE file , so just ./#FontAwesome will work.
Yes, as I said before and as explained in the text tutorial, using # syntax means you are referencing local/app fonts. The font will be requested to the font provider you specify at startup. If it is a LocalFontProvider it will look for the font in the file system at the root specified. If it is an EmbededFontProvider it will require you embedd the font in code. Or you can write your own font provider to look for the font as you want.

Who is online

Users browsing this forum: No registered users and 3 guests