Icon not found in WPF application - wpf

I have set Icon= "icon.ico" in MainWindow.xaml but it does not find it. I got the icon in the final build directory and in project directory. Absolut path works.
My question is: where does the Icon= "icon.ico points to from my xaml file and how to properly reference relative path?

Solved it by adding
<ItemGroup>
<None Remove="icon.ico" />
</ItemGroup>
<ItemGroup>
<Resource Include="icon.ico" />
</ItemGroup>
to my .csproj.

Related

the element <projectreference> beneath element project is unrecognized

this is the error i am facing while adding the project reference to the .csproj file
, I am developing CRUD using ASP.net core + react js by taking help of microsoft learn here is the link:https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-asp-net-core-with-react?view=vs-2022
project reference
error i am getting
i am facing this issue can anyone help?
enter image description here
Change your .csproj file like below, the issue could be fixed.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FootBallManagement_reactjs\FootBallManagement_reactjs.esproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
</Project>

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.

WPF applying theme

i have a WPF project using VS2010 that i'ld like to add a theme to it
What i've done is :
downloaded the WPFToolkit.msi, and ran it.
downloaded the Aero.NormalColor.xaml (for example) and added it to the project.
As references i added :
WPFToolkit
PresentationFramewoek.Aero
In the App.xaml i added this :
ResourceDictionary Source="Aero.NormalColor.xaml"
The project run with no errors but still the theme not applied.
So can anybody tell me what i've been missing here ?
Welcome to SO! Try this:
<ResourceDictionary Source="/PresentationFramework.Aero,
Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35,
ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml" />

WPF Custom fonts problem

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".

Silverlight unable to resolve References when switching from Debug to Release

I am using: Silverlight Version 4.0, 100% F# solution. I am having an issue when switching the Target Configuration from debug to release. Everything compiles fine in debug mode, then in release I get the following:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9):
warning MSB3245: Could not resolve
this reference. Could not locate the
assembly
"System.ComponentModel.DataAnnotations".
Check to make sure the assembly exists
on disk. If this reference is required
by your code, you may get compilation
errors.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9):
warning MSB3245: Could not resolve
this reference. Could not locate the
assembly
"System.Windows.Controls.Data.Input".
Check to make sure the assembly exists
on disk. If this reference is required
by your code, you may get compilation
errors.
The Item group in the project file lokos like:
<ItemGroup>
<Reference Include="FSharp.PowerPack">
<HintPath>C:\Program Files\FSharpPowerPack-2.0.0.0\Silverlight\v3.0\FSharp.PowerPack.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core">
<HintPath>$(ProgramFiles)\Microsoft F#\Silverlight\Libraries\Client\$(SilverlightVersion)\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Browser" />
<Reference Include="System.Windows.Controls">
<HintPath>bin\Debug\System.Windows.Controls.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Data">
<HintPath>bin\Debug\System.Windows.Controls.Data.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Data.Input" />
<Reference Include="System.Windows.Controls.DataVisualization.Toolkit">
<HintPath>bin\Debug\System.Windows.Controls.DataVisualization.Toolkit.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Input">
<HintPath>c:\Program Files\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.Windows.Controls.Input.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Layout.Toolkit">
<HintPath>bin\Debug\System.Windows.Controls.Layout.Toolkit.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Navigation">
<HintPath>bin\Debug\System.Windows.Controls.Navigation.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Controls.Toolkit">
<HintPath>bin\Debug\System.Windows.Controls.Toolkit.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Data">
<HintPath>bin\Debug\System.Windows.Data.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
</ItemGroup>
Obviuosly some Elements have HintPaths while others do not, and while some have hintpaths there appear to be absolute and relative paths...
Can anybody help me out? Thanks in advance.
OK so I removed the references and then readded them and they came into the project file in the format of:
c:\Program Files\Microsoft
SDKs\Silverlight\v4.0\Libraries\Client\System.ComponentModel.DataAnnotations.dll
for both of the references. It all compiles - in both versions. Any hint on th HintPaths? How they are used and how and when they are generated? And why when I tried to modify the proj file by hand it didn't seem to matter (still didn't compile even though VS told me it reloaded)?
Thx
Sounds like you moved the project from another machine and you don't have the Silverlight Toolkit and the WCF RIA Services installed on your machine.
Clean your solution, close your Visual Studio and install what's missing.
FYI, there is a bug in the shipped Microsoft.FSharp.targets that may interact with this. You can add this line
<FrameworkRegistryBase Condition="'$(TargetFrameworkIdentifier)'=='Silverlight'">Software\Microsoft\Microsoft SDKs\$(TargetFrameworkIdentifier)</FrameworkRegistryBase>
inside a <PropertyGroup> (just below the <Tailcalls> element is a good spot) inside Microsoft.FSharp.targets to fix it. I don't know if this relates to your problem (it sounds like it may not), but just a heads-up in case.
(The fact that you get a HintPath (even if you do things right) may also be the result of a bug in the F# project system.)
One possible strategy if you need a workaround is to check in a copy of DLLs you need to reference in a fixed spot (relative to your projects) under source control, and then reference those DLLs via the 'fixed' relative paths.

Resources