This may well be a stupid question, but I cannot find an answer...
I am just getting started with WPF, and am trying to add a ResourceDictionary to my project.
this one here:
https://monotone.codeplex.com/
So I downloaded the zip file, and unzipped it to:
MyProjectDir/MonoTone
I have added the following to my App.xaml
<Application x:Class="TestWPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestWPF"
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Monotone/Monotone.Colors.xaml" />
<ResourceDictionary Source="Monotone/Monotone.Brushes.xaml" />
<ResourceDictionary Source="Monotone/Monotone.MahApps.xaml" />
<ResourceDictionary Source="Monotone/Monotone.xaml" />
<ResourceDictionary Source="Monotone/Monotone.ExtendedWPFToolkit.xaml" />
<ResourceDictionary Source="Monotone/Monotone.ColorBox.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
as here:
https://monotone.codeplex.com/wikipage?title=Installing%20Monotone&referringTitle=Documentation
Now Intelsense is underlining the xaml paths, and cannot find the files.
I have added a reference to the dll. What am i missing?
Thank you.
First, try including the Monotone catalog in the solution by clicking on show all files icon in solution explorer.
Second, as shown in below screen, pinpoint the exact path as in the first line of example.
To explicitly answer your question: Visual Studio was complaining because you needed to add the Monotone files (from the release zip) to your project under a folder called "Monotone".
Janis S's answer already stated this.
Unfortunately, the Monotone project contains a few dependencies on other projects... Specifically, you'll notice that it references the ColorBox control, which can be found on CodePlex, and it also depends on some Xceed assemblies. Your project will not build without those.
A few examples of the references to external dependencies are:
xmlns:xtk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:nc="http://schemas.ncore.com/wpf/xaml/colorbox"
xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Converters;assembly=Xceed.Wpf.Toolkit"
xmlns:Behaviours="clr-namespace:MahApps.Metro.Behaviours"
xmlns:mm="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mmm="http://metro.mahapps.com/winfx/xaml/shared"
At this point you have three options
remove all references to the external assemblies.
OR figure out which assemblies are needed and add references to those as well.
OR find a different dark theme to use.
Option 3 is probably the best one at this point as CodePlex is shutting down soon and Monotone does not appear to be maintained. A quick Google search results in a few free WPF Dark Themes that are still functioning that could be used instead.
Edit
If you really want to use Monotone, go to their downloads page and grab the sample application. All of the missing DLLs are included in that download (you will need to include those in your project and add them as references).
I might be very late to the party, but to clarify things:
I am the creator of Monotone (which was a theme I used for an IDE I developed which is now obsolete). I don't mind if you pick another/better dark theme for your application, it's pretty old at this point.
Monotone is now 'maintained' on GitHub. Well, it's more or less stale at this point since I'm not into C# anymore. But if you (or anyone else) have a specific problem with it, feel free to submit an issue on GitHub or a pull request that solves it.
You only need to add the XAML-files for Monotone.Colors.xaml, Monotone.Brushes.xaml and Monotone.xaml to the ResourceDictionary.MergedDictionaries for the default WPF controls. Include in this order. If I remember correctly the files have to be set to EmbeddedResource. That's it.
Monotone.ExtendedWPFToolkit.xaml is only needed if you use (and want to theme) the ExtendedWPFToolkit controls. Sames goes for Monotone.MahApps.xaml and Monotone.ColorBox.xaml. So, these are optional. It's kept in separate files to avoid dependencies to libaries you might not use
You don't need the DLLs for styling the standard WPF controls
Because of the shutdown of CodePlex the Wiki-Pages are gone. I might dig into the code and recreate it on GitHub (or even better add it to the repo itself), that you have a helpful documentation.
As pointed out, the SampleApplication contains a working example which you can use as a template and/or to understand how it works
Related
I am building a WPF desktop app with .net framework 4.7.2. and need some help for merging resource dictionaries.
I have 1 solution with 2 projects:
Main parent project (ProcesingDesktopHub) which only has a nav bar and depending on user click its injecting a view/viewmodel from child project (DopisiUzPovrate).
Inside the parent project I have created a ResourceDictionary.xaml with some colors etc. and I want to be able to propagade that dictionary to the child project so it can be used if I run the child project separately from the parent (testing, designing etc.)
I have tried putting this inside the child but it does not work:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://ProcesingDesktopHub:,,,/ProcResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
I hope I described my question correctly.
A solution cannot have circular references between projects.
Since the parent project refers to the child, then, accordingly, the child cannot refer to the parent in any way.
One of the solutions: move the shared resources (if you need not only resources, but also types, controls, etc.) to a third project that will be referenced by the parent and child projects.
Second variant: if you do not provide for the use of the child project outside the parent project, then you can use the design-time resource creation technique described here: https://stackoverflow.com/a/17712041/13349759
And in runtime, the resources of the parent project will be used.
Design time sounds good but I would need to run the parent project for debugging purposes each time if I understood it correctly.
If you want to separately debug a child project, then creating a third project with shared resources will be the best varaint.
In addition, if you ALWAYS use the parent project only together with the child, then pay attention to the answer from #MuhammadSulaiman.
Move ResourceDictionary.xaml to child project (i.e. DopisiUzPovrate), and the structure of resources in ProcesingDesktopHub (i.e. Application.xaml) would be like this
<Application>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/DopisiUzPovrate;component/Path/To/ResourceDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Converters, Colors and styles -->
</ResourceDictionary>
</Application.Resources>
</Application>
Update: In case you have one application (ex. ProcesingDesktopHub) and several modules (DopisiUzPovrate1, DopisiUzPovrate2, etc...), and all of these would use shared resources, then you have to create a SharedModule that hosts the shared resources and once you reference the ResourceDictionary.xaml in desktop application, it'd be available to the modules and application at runtime..
I'm working on an extension for Visual Studio and I'm currently looking at using WPF instead of Forms for the template wizard.
I've got it all working with Forms but I much prefer the look of and working with WPF, but I'm not sure if what I'm trying to do is possible - or how I should go about doing it properly.
My VSIX consists of your typical layout, it's a solution with 3 projects;
1. MyProjectTemplate (C# Project Template)
2. MyProjectVSX (C# VSIX Template)
3. MyWizardWPF (WPF App)
I'm also using MahApps.Metro to make it look a bit sleeker. Added (via NuGet) and referenced by both MyProjectVSX and MyWizardWPF.
And while it works - the WPF shows up when I go to create a template - it is completely and utterly missing any styles. It basically just looks like a Windows 95 application.
I'm assuming this is related to the App.xml and it being unable to locate it. But I'm at a complete loss at how to tie all of this together. I get a bunch of warnings that it was unable to find various style related things. For example;
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='MahApps.Brushes.IdealForeground'
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='MahApps.Brushes.ThemeForeground'
I've tried playing around with the ResourceDictionary URIs, copying the App.xml to my VSX project. Tried building it as a class library instead of an application but to no avail.
Is what I'm trying to achieve here feasible...?
Well I was able to reference MahApps.Metro. Seems like I was vastly over-looking it all. I'm still not sure if this is the right way to do it, however. But it works.
I referenced MahApps.Metro inside the Window.xaml itself instead of via the App.xaml, like so;
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="/MahApps.Metro;component/Styles/Fonts.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="/MahApps.Metro;component/Styles/Themes/Dark.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
This also works if I create a WPF User Control which will make the overall project a bit less bloated - but the designer will not be using MahApps.Metro styles. I have yet to find a fix for this.
I am trying to build a network with all the solution classes as nodes - connected to their parents (classes using them) and children (classes they use). From there I want to get the "critical paths" from the root-class(es). By critical paths I mean the paths in the network that originates at the root(s).
I know you can set a specific project in a solution as the startup project. When the solution is built and run, what class in the startup project is the root or main class than is run first? - that would be my root class.
All projects in the solution are WPF projects.
In a wpf project,by default, the first class that is called is the App class.
The class looks like this:
App.xaml.cs
public partial class App : Application
{
}
App.xaml
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
As you can see there is StartUpUri in there which contains what window will show up first.
In general this is set for each project separately and it differs depending on the technology. It is easy accessible by Visual Studio, just go to the project configuration, there in Application tab you will see Startup Object, that can be selected from those that fit the requirements. See screenshot.
For Winforms this is persisted in the App.config as:
<StartupObject>OBJECT_NAME</StartupObject>
For WPF you will find it by default in App.xaml. However this could be customized in ApplicationDefinition section of the csproj file and other files could be potentially used. For Web or WCF it will be even more different as there is no real startup object, just default page.
As you can see there is no one simple answer; however for only WPF you should be able to get a fairly complete solution. Bear in mind that there are usually class libraries projects included as well.
Basically I'm having the same issue as this (unanswered) question: IOException was unhandled - Cannot locate resource app.xaml
When I open my project in Visual Studio 2010 and start debugging, I get "IOException was unhandled: Cannot locate resource app.xaml". Rebuilding the solution DOES NOT work, I have to somehow modify my app.xaml file (adding an empty line, for example) in order to run my project successfully.
Additional details:
My solution consists of two projects: My main (WPF) application and a test project.
I have read about issues if the solution was converted from Visual Studio 2005. This is not my case. My project was originally created with Visual Studio 2010. Maybe (I don't remind exactly) it was sometime targetted at .Net Framework 3.5 or .Net Framework 4.0 Client Profile, but it currently is configured to work with .Net Framework 4.0
Both projects have different names, if that matters. The first is called MyApplicationName (assembly name and default namespace) and the second MyApplicationName.Test (assembly name and default namespace too)
Most classes in my main project are internal (including the View classes), but my App class is public
The main project exposes its internal components to the test project (using [assembly: InternalsVisibleTo("MyOtherProject")])
I'm using MVVM (with MVVM Light), but I'm not using a ViewModel 'resolver'/container/bootstrapper/MEF or related things. I just map my ViewModels to their respective views using DataTemplates and create my ViewModels manually (if that matters).
My App.xaml includes other three xaml resource files. I include my App.xaml here:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/StyleDictionary.xaml" />
<ResourceDictionary Source="Resources/CommonResources.xaml" />
<ResourceDictionary Source="Resources/ViewModelMappings.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
I override the OnStartup method from my App class to manually handle the startup logic, if that matters. I also wrote a static constructor there to initialize the DispatcherHelper from MVVM Light:
public partial class App : Application
{
static App()
{
GalaSoft.MvvmLight.Threading.DispatcherHelper.Initialize();
}
...
}
Things like this could happen when you change the target framework of a project. You could recreate the projects as new applications which target .Net 4 from the start, and add all your code files as existing items.
Another thing that comes to mind is the casing of the app.xaml file name. It might be case sensitive in some contexts and not case sensitive in others, so have you tried changing that? On my system, by default it is App.xaml. Since in the error message it is app.xaml, it might be worth while doing a case sensitive search through the project files with a text editor and changing all occurences of the name to App.xaml.
I don't know if this is a definitive solution, but it seems to be working so far:
Open your csproj file with Notepad
Search App.xaml and App.xaml.cs. Ensure every reference to this file has the same case. The files were called App.xaml and App.xaml.cs, so I left the references like that.
Previously I had something like this:
<Compile Include="app.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
So I modified it and now it is:
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
Another thing I did was look for BootstrapperPackage and remove the old versions of .Net Framework from there, though I don't think that's a good idea if your project uses libraries that depend on old versions of .Net. I'm not sure that was causing the problem too.
I'm adding a new WPF project to an existing Visual Studio solution and would like to reuse a bunch of code (C# and xaml) from an existing project within the solution.
I've created the new project and added existing files as follows:
Right click project
Add -> Add Existing Item
Find the file to reuse, use the arrow next to "Add" and "Add as Link"
I now have a nice project set up with all the proper links. However, XAML chokes on these links. For example:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Resources\Elements\Buttons\Buttons.xaml" />
<ResourceDictionary
Source="Resources\Elements\TextBox\TextBox.xaml" />
</ResourceDictionary.MergedDictionaries>
The files "Buttons.xaml" and "TextBox.xaml" exist as links in my new project. The project builds, but when I run, I get the following XamlParseException:
'Resources\Elements\Buttons\Buttons.xaml'
value cannot be assigned to property
'Source' of object
'System.Windows.ResourceDictionary'.
Cannot locate resource
'resources/elements/buttons/buttons.xaml'.
It seems like the XAML parser is requiring an actual copy of these XAML files to exist in my new project, instead of links.
This is exactly what I'm trying to avoid. I want my project to share these files so that any changes get transferred to the other project without hunting and copying.
Any insight is appreciated!
Linking to an external XAML file does not create a file where the link exists in a project structure, as you have noticed.
My advice is to use relative links in the MergedDictionaries references. If the XAML to reuse in another project is called Common, the Source property of the first nested ResourceDictionary could be:
..\Common\Resources\Elements\TextBox\TextBox.xaml
which is actually the path that you used to add the existing item.