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" />
Related
I was trying to use WinUI so I installed the plugin Microsoft.UI.Xaml (2.4.2) from Nuget
and followed the instructions which says add This <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/> to my App.Xaml
and here is my App.Xaml file
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="MainWindow.xaml">
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</Application.Resources>
</Application>
but it says:
The tag
'XamlControlsResources' does not exist in XML namespace
'using:Microsoft.UI.Xaml.Controls'
i tried older versions from WinUI plugin and tried .Net Core and Framework but still having this problem
I believe this WinUI 2.4.2 library is only compatible if you create a UWP application, not a WPF app.
Having said that, according to this documentation from Microsoft, starting with WinUI 3, you will be able to do this in WPF.
Add
<package id="Microsoft.UI.Xaml" version="2.5.0-prerelease.200812001" targetFramework="native" />
If you browse and can't find it add a line containing the above to the packages.config file check installed and the wait for Restore to show up in Nuget tools.
Make certain a reference is in the <Import Project="packages\Microsoft.UI.Xaml" version="2.5.0-prerelease.200812001..."
And also the <Error Condition="!Exists('packages\Microsoft.UI.Xaml" version="2.5.0-prerelease.200812001..."
in the .vcxproj file for your project.
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.
I'm trying to create silverlight project using eclipse.
i've used PlaneProjection tag in xaml page.
this automatically generated code in CSharp..
there i'm getting error like,
The type or namespace name 'PlaneProjection' could not be found (are you missing a using directive or an assembly reference
Page.g.cs /Hekllo/obj/Debug line 44 Problem Full Build Marker
what i've understood is there is no reference available here for PlaneProjection.
Please help me.
Your project must have a reference to System.Windows.dll
Typically it can be found here:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\vX.X\System.Windows.dll
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".
I downloaded the source code of
http://silverlight.net/learn/videos/silverlight-videos/twitter-search-monitor/#video
Visual Studio 2010 converted it to SL4. When running it complains
Error 3 The type or namespace name 'BusyIndicator' does not exist in the
namespace 'System.Windows.Controls'
(are you missing an assembly
reference?) C:\tutorials_dotnet\silverlight\HDI-Silverlight-source-TwitterSearchApp_CS\TwitterSearchMonitor\obj\Debug\Views\Search.g.cs 38 42 TwitterSearchMonitor
The BusyIndicator is not found in the Silverlight SDK, its in the Toolkit which you need download and install.
Once installed add a reference to the System.Windows.Controls.Toolkit dll.
Add this namespace alias to the page using the BusyIndicator:-
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
You then use toolkit: alias to define it:-
<toolkit:BusyIndicator x:Name="busyIndicator>
<!-- your page content -->
</toolkit:BusyIndicator>