WPF Custom fonts problem - wpf

This is really weird. In Blend 4, the custom font works when I see the application in the designer, but when I run it, the font is gone and it goes back to arial or something. This is my XAML:
<TextBlock Text="Text G" FontFamily="/ProjectName;component/Fonts/#Futura Lt BT" FontSize="48" Background="#FFC44747" />
The font is in a folder called "Fonts" and the control in which I'm trying the font is in a folder called "Controls". I know it must be a problem with the relative position of the "Fonts" folder to the "Controls" folder, but I've already tried a lot of stuff and it doesn't work.
Also, the XAML markup I put up there is what Blend creates when I select the custom font. The font is copied as a resource all right (I already check the csprof file and it's there).
Any ideas? This has been kicking my butt for a couple hours now.
Thanks.

While I understand that this is far too late to help the question author, I am leaving this to help future viewers of this question.
The information in this answer comes from the Packaging Fonts with Applications page on MSDN:
Adding Fonts as Content Items
You can add fonts to your application as project content items that are separate from the application's assembly files. This means that content items are not embedded as resources within an assembly. The following project file example shows how to define content items.
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Other project build settings ... -->
<ItemGroup>
<Content Include="Peric.ttf" />
<Content Include="Pericl.ttf" />
</ItemGroup>
</Project>
In order to ensure that the application can use the fonts at run time, the fonts must be accessible in the application's deployment directory. The element in the application's project file allows you to automatically copy the fonts to the application deployment directory during the build process. The following project file example shows how to copy fonts to the deployment directory.
<ItemGroup>
<Content Include="Peric.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Pericl.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Adding Fonts as Resource Items
You can add fonts to your application as project resource items that are embedded within the application's assembly files. Using a separate subdirectory for resources helps to organize the application's project files. The following project file example shows how to define fonts as resource items in a separate subdirectory.
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Other project build settings ... -->
<ItemGroup>
<Resource Include="resources\Peric.ttf" />
<Resource Include="resources\Pericl.ttf" />
</ItemGroup>
</Project>
When you add fonts as resources to your application, make sure you are setting the element, and not the element in your application's project file. The element for the build action is not supported.
The following markup example shows how to reference the application's font resources.
<TextBlock FontFamily="./resources/#Pericles Light">
Aegean Sea
</TextBlock>
Please follow the above link for details on referencing Font resources from code and other useful information.

Everywhere over the internet and in books it says that when you add a font you should set the Build Action to "Resource" (example here). And it 'worked for a while. Anyway, to fix my problem, I had to change it from "Resource" to "Content".

Related

Define variables in csproj SDK style

I have converted a WPF project to the new csproj SDK format. It shows some properties such as:
Company: $(Authors)
Where do I define the variable $(Authors) and similar such variables? I am building my project both locally and in Azure DevOps.
This is MSBuild specific, it does not depend on SDK project style in particular, see:
Define and reference properties in a project file
Define a tag with the name of the property inside a PropertyGroup.
<Project Sdk="Microsoft.NET.Sdk">
<!-- ... -->
<PropertyGroup>
<Authors>John Doe, Jane Doe</Authors>
</PropertyGroup>
<!-- ... -->
</Project>
Since you refer to a property named Authors, you probably mean a special property that is used for NuGet packaging, see pack target inputs and Package properties.

dotnet pack "The element <package> is unrecognized"

Im trying to create a NuGet package of a dotnet new template. I created a nuspec file to set the details of the package, and it sits adjacent to my contents foler, which contains everything I want packaged up:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<!-- The identifier that must be unique within the hosting gallery -->
<id>My.EpiserverCMS</id>
<!-- The package version number that is used when resolving dependencies -->
<version>1.0.0</version>
<!-- Authors contain text that appears directly on the gallery -->
<authors>Me</authors>
<description></description>
<!--
Owners are typically nuget.org identities that allow gallery
users to easily find other packages by the same owners.
-->
<owners>me</owners>
<!-- License and project URLs provide links for the gallery -->
<licenseUrl></licenseUrl>
<projectUrl></projectUrl>
<!-- The icon is used in Visual Studio's package manager UI -->
<iconUrl></iconUrl>
<!--
If true, this value prompts the user to accept the license when
installing the package.
-->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<!-- Any details about this particular release -->
<releaseNotes>First Release</releaseNotes>
<!--
The description can be used in package manager UI. Note that the
nuget.org gallery uses information you add in the portal.
-->
<description>dotnet new template for Episerver CMS</description>
<!-- Copyright information -->
<copyright>Copyright ©2018 Me</copyright>
<!-- Tags appear in the gallery and can be used for tag searches -->
<tags>web episerver cms</tags>
<!-- Dependencies are automatically installed when the package is installed -->
<dependencies>
</dependencies>
<packageTypes>
<packageType name="Template" />
</packageTypes>
</metadata>
<!-- A readme.txt to display when the package is installed -->
<files>
<file src="README.md" target="" />
<file src="**" exclude=".vs\*,packages\*,**\*.mdf,**\*.ldf,**\*.log"></file>
</files>
</package>
But when I run dotnet pack I get the error:
error MSB4068: The element <package> is unrecognized, or not supported in this context.
Which I really dont get. Isnt package supposed to be the root element in a .nuspec file?
dotnet pack doesn't support packing nuspec files. It only supports msbuild projects that contain a Pack target.
You can create a csproj project and use the NuspecFile property or use nuget pack through a nuget.exe version from http://nuget.org/downloads or through a nuget executable provided by the mono framework on non-windows platforms.
dotnet pack does support nuspec files. However, you have to pass them a couple specific configuration flags and add a dependency to your project. See the documentation here: https://learn.microsoft.com/en-us/nuget/reference/msbuild-targets#packing-using-a-nuspec

How to add embeded resources dynamically on CI server to csproj file if not there?

Is there a way to check if a resource (example given below) is added in a csproj file? If not, add it properly to the csproj?
<EmbeddedResource Include="Properties\some.resources" />

DNN custom skin and css deployment

I am new to this and trying to figure this out. I have created a internal.ascx page and a Internal.css file for my internal page for a website. If I create a new page in DNN and apply this new skin it doesnt seem to apply the CSS. I copied the both ascx and css file to the _default/Skins/ folder.
Have also tried adding in the css via the following code
<dnn:DnnCssInclude runat="server" FilePath="/Internal.css" PathNameAlias="SkinPath" />
Nothing seems to be working. Have cleared my cache and tried different machine to view the page. But the style is still not coming through.
Thanks in advance
Create a new folder in the _default/Skins/. For example, call the folder "Internal" (/Portals/_default/Skins/Internal). Copy your ascx and css skin files into there. Rename the css to "skin.css". You shouldn't need to reference it in the ascx since DNN will pick it up based on the name.
Also, the reason your CSS include statement may not have worked was because filepath "/Internal.css" was probably trying to look for it in the root of the website. I would think it would simply be "Internal.css". But you could verify in Firebug what path it generated.

WPF - Import image as resource

In WinForms it is possible to import an image as a resource, and the image would still work when compiled in the /bin/Debug folder.
I can't figure out how to get this working in WPF, when I run the application the image doesn't load, because the image is saved in /Projects/AppName/images/, and the application is compiled into /Projects/AppName/bin/Debug when I run it in Debug mode.
Do I simply need to make a copy of my Images folder and put it where the application is compiled? Or is there another way. Here is my code which displays my image:
<Image Width="300">
<Image.Source>
<BitmapImage DecodePixelWidth="300" UriSource="/images/jamsnaps-dark.png" />
</Image.Source>
</Image>
Create a folder (e.g. images) in your Visual Studio Project.
Add the image file(s) to that folder.
Set their Build Action to Resource (in the Properties window, see second image in this answer).
Then write the UriSource property like you already did:
UriSource="/images/jamsnaps-dark.png"
That URI is effectively a Resource File Pack URI, where the prefix is automatically added by the XAML Parser.
In code behind, you would write
bitmap.UriSource = new Uri("pack://application:,,,/images/jamsnaps-dark.png");
Two options :
1) Go out from bin/Debug and in to your application folder by ../../ and then to your image.
<Image>
<Image.Source>
<BitmapImage UriSource="../../images/jamsnaps-dark.png" />
</Image.Source>
</Image>
2) Compile your images as Content from properties in the context menu on the image file , and then when compiled they would be placed in been debug.
I don't remember if you also need to tell them to copy local also in properties ( i'm not near a computer at the moment so i can't check .
Add the image to your project directory
In the solutions explorer, right click the image and select Include in Project
Build Action should be set to Resource by default.
You can then start to use the image path relative to the root e.g. images/text.jpg if you put it in a folder called images.

Resources