Xamarin.Forms - Loading Font from Shared Project - c#

I've made a big library to use with all my Xamarin.Forms projects. This lib defines styles, shares reusable code fragments, and so on. Now because I use FontAwesome multiple times in different projects, I want to share the .ttf-File with the library.
Actually the font is stored in my UWPs Assets/Fonts/ folder and is loaded like this:
<On Platform="UWP" Value="Assets/Fonts/fontawesome-webfont.ttf#FontAwesome" />
This works quiet good, and no need to implement a custom rednerer (at least for UWP).
The Problem is that the Font does not seem to get loaded, when I define it as a EmbeddedResource, so I don't know how to load it from the library Project.
Maybe someone did such a thing ever before and could me tell the solution. Thanks!
Edit:
I recreated a project, but I cannot load the Font-File without installing it on my Computer. You can download the Project here: https://github.com/DirtyNative/FATest

To make the font usable, set its build action to Content and you can refer to it as:
FontFamily="ms-appx:///LibraryName/Path/To/Font.ttf#Name"
It seems UWP is unable to load embedded resources from XAML, or at least I haven't yet found a way which would work.

Related

Visual Studio: What's the correct way to reference resources across projects?

An .xaml image location in a secondary reference is not becoming the correct resource location during runtime, it refers to the primary reference resources folder instead. How can I change this?
Background -
I have a solution with several projects. The important three projects here are
a WPF project which builds as a class library
a default class
library
a console app for testing
The WPF project has a .png image in its resources. In the MainWindow created it's called via:
<ImageBrush
ImageSource="pack://siteoforigin:,,,/Resources/MyDemoImage.png"
Stretch="Uniform"/>
When I run an instance of the WPF window directly through the console app, it works fine. The resource reference becomes during runtime:
C:\Users\me.me\Documents\Visual Studio 2015\Projects\sol\
WPFProjectName\
bin\Resources\MyDemoImage.png
But if I create a reference to the WPF project within the class library project then call an instance of the class library, the address becomes
C:\Users\me.me\Documents\Visual Studio 2015\Projects\sol\
ClassLibraryName\
bin\Resources\MyDemoImage.png
So this "pack" address becomes a reference to the class library resources rather than the WPF project resources folder.
Now, I think I could simply add the resource to that middle-man class library too, but I'm wondering if there's some correct way to reference a "secondary" resource, so I only have to add images once?
By the way, the error I get when I try to compile this is System.Windows.Baml2006.TypeConverterMarkup - I've found answers regarding this but tried what they say to no avail (mark image as copy always etc.)
Change
pack://siteoforigin:,,,/Resources/MyDemoImage.png
to
pack://application:,,,/AssemblyName;component/Resources/MyDemoImage.png
Thanks to #Clemens for his advice. This worked great.
I just wanted to answer and share a bit of other frustration-gathered knowledge I found while experimenting with this.
Using pack://application:,,,/AssemblyName;component/Resources/MyDemoImage.png worked great for me for my first image. I then had loads of trouble trying to do the same thing for a 2nd/ 3rd image. It kept compiling ok but on runtime the inner exceptions were throwing out that it couldn't find "resources/mydemoimage.png"
The reason for this was due to the BuildAction on the images. I'd been playing with the different types, some of which worked for my local copy (e.g. setting BuildAction to Embedded Resource actually fixed the initial issue I was having) BUT for the pack://app... to work, compile and then carry through to install and be instanced in another application (e.g. VBA in Excel)...
The BuildAction MUST be Resource
I was extremely lucky that I'd set this by chance before trying Clemens' answer because if I hadn't I would have assumed it just didn't work! But it does!

Creating Wp8 Unity Plugin in Unity 5.0

I have a windows phone 8.0 plugin created for an app. This app worked perfectly fine in Unity 4.5. I recently updated my Unity to 5.0. I also saw all the needed alterations.
Initially, we needed to create two plugin dlls. One actual and one empty simply like an interface for the editor. This went pretty well in unity 4.5
Now i open the same app in Unity 5.0 by upgrading it. and i am unable to build it for wp8 anymore. I set the inspector platforms correctly to WP8 player for my plugin dll.
But, i keep getting errors like ::
1. Plugins are colliding.
2. There are errors in the script (which are actually not)
3. Cannot load classes from module.
4.System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
etc.
Can anybody help me? I have tried several things already but none seems to work.
I tried :
1. Reimporting everything
2. Rebuilding the dlls.
3. Removing the empty interfaced dll for editor
4. Changing the folder structure for plugins. (Default being
Assets/Plugins/WP8)
I am stuck here since two days now.
Well, it's too late to reply. But anybody else stuck in same problem may get help.
One should know that WP8 Plugins are based on real and fake dlls in order to work in Unity Editor.
In Unity 5, you can specify platform to dll, irrespective of folder structures. However if you put dll in Assets->Plugins->WP8. Unity will mark it as WP8 dll.
Solution is,
1- Put Fake dll in Assets->Plugins->AnyFolder->plugin.dll, where any AnyFolder is other than WP8 folder. Mark it as Editor instead of Any Platform (from inspector [Select platform for plugins]).
2- Put Original dll in Assets->Plugins->WP8->plugin.dll, mark it as WP8Player
3- Keeping original dll selected, in Platfrom Settings [Inspector] modify settings like, CPU -> Any CPU, check mark on Don't Process, Select placeholder.
Placeholder drop down would show the path of fake dll, just set it.
Now you are all done :)
You must set the editor DLLs to "Editor" instead of "Any Platform" and the WP8 plugins to "WP8Player" in the plugin settings.

Dynamically embed application manifest

I know how to create app.manifest statically from inside Visual Studio. But is there any simple way of dynamically embedding application manifest file to an existing assembly?
I don't wish to use tools like mt.exe as I can't redistribute them at the client machine.
Apparently, I couldn't find a way to dynamically embed app.manifest to an existing assembly, and surprisingly this question didn't even get a single comment. So, I changed my approach of solving the problem. Now, I am compiling my assembly dynamically (at the client site) and using custom resource containing my custom app.manifest.
Hope this helps someone with a similar problem.

C#: Making a file editable from one project, but including it in two

I've currently got a solution where a certain class is used from several C# projects, some Silverlight, some regular. For compatibility reasons I cannot create a single project for these utility classes. At first I solved the problem by making the class library project a silverlight one, so that it could be referenced by all other projects.
However, I ran into another problem that made it impossible to use a Silverlight project as the class library. So I resorted to making two separate class library projects: one Silverlight, one regular. In C++ it's possible to add a project file to two projects, while only having one physical file on disk. I noticed that in C#, it automatically makes a copy when adding the file to a second project. I solved this with a build event that copies the file from the regular library to the Silverlight one when the Silverlight project is built.
This all works, so technically the problem is solved. However, it's gotten too convoluted for my taste. Also, other programmers who are unaware of my solution might start to edit the dependent (Silverlight) file, and get unexpected results.
So my question is, do you know of any good reasons to solve these two issues properly? How would you solve it?
If you need 1 file on disk do not use the standard "Add" when adding the file to your project but click on the arrow next to it in the dialog and select "Add as link", however this does not prevent it from being edited (you'll have to look into other options there, I'm not aware of any)
I think you are talking about linking. Have a look here:
http://support.microsoft.com/kb/306234
Hope this helps.
have the file in one project then in the other projects where you want to have it as well do Add Existing Item, select the file and see the Add button in the dialog has a small arrow, select Add as Link from there and you are set. :)

Expression blend convert example from Silverlight into WPF

Hey! I was looking at a cool layout example in particular the V3FluidLayout.xaml found inside this set of examples : http://gallery.expression.microsoft.com/en-us/DynamicLayoutTrans
Anyhow - this appears to be a silverlight app - it runs within a browser. I am trying to pull the V3FluidLayout example into a WPF app - and struggling.
I "add an existing item" pulling the .xaml file into my project. When it goes to compile it, the following errors are found :
Are these artifacts Silverlight? The following is the xaml code within the V3FluidLayout.xaml file
http://pastebin.com/h9ujUax6
Can anybody help me pin why this is not working - and how I can convert that xaml code to work inside my wpf app.
Thanks
Andy
Basically (and from only a quick glance), you'll need a reference to the WPF versions of System.Windows.Interactivity and Microsoft.Expression.Interactions - they are part of Blend. Actually look at the references of that project and find the exact same references, only for WPF.
It looks like they contain pretty much the same classes for both WPF and Silverlight, so I think it should work in the end.
Add references to the interactivity assemblies found here:
C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries
You need to install the Blend SDK to get them, the come with Blend also.

Categories