WPF Merged Dictionaries - wpf

i'm trying to use MaterialDesginThemes and HandyControl ResourceDictionary together but after i run my application it seems that it only recognising Handycontrol recourses at then i find out that application resources can only recognize the last line in the recourse dictionary can any one help how to fix this problem
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Purple.xaml" />
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Related

WPF: How to remake Mahapps Metro application to class library?

I have a WPF Mahapps Metro style application.
That is the MainWindow containing Usercontrol, and inside it works with other Usercontrols like Wizard Pages.
Now I am trying to remake it to a class library to use it in WiX Bootstraper application.
The one of problems is: where place resources which are in
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
I have placed it to the main Usercontrol xml but it is an error:
<UserControl.Resources>
<ResourceDictionary> <------------x:Key required?
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<DataTemplate DataType="{x:Type viewModel:ViewModelAlreadyInstalledPage}">
<view:AlreadyInstalledPage/>
</DataTemplate>
...
You have to put the DataTemplate inside the ResourceDictionary:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
<DataTemplate DataType="{x:Type viewModel:ViewModelAlreadyInstalledPage}">
<view:AlreadyInstalledPage />
</DataTemplate>
</ResourceDictionary>

Controls styles not found in MahApps 1.1.3-alpha225

I was using the stable version on nuget and changed to 1.1.3-alpha225 also from nuget. I did that so I could call dialogs through the ViewModel. But now I'm getting this error:
An error occurred while finding the resource dictionary "pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml"
All other dictionaries are ok:
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
The controls is the only one giving error:
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml"
Does anyone know if it changed on the new version or if there's a known bug?

XAML ResourceDictionary same-assembly reference

I'm developing a WPF control library, and I need to reference a resource dictionary defined in the same assembly.
I managed to get it working with a separate-assembly reference.
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/MyLocalAssembly;component/Foo.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
While with a same-assembly reference it doesn't work, and raises an exception ("Cannot locate resource 'Foo.xaml'.") at load time. Note that in the designer everything works fine, no matter which method I use.
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/Foo.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Don't use absolute path for the resource dictionary. Simply use relative path reference.
For example,
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="folder/Foo.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>

the resource "" could not be resolved in design time

My resource merged in App.xaml. but in design mode not found
in Run time it found and work correctly
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/Styles/Main.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Style="{StaticResource pnlRibbon}" the resource "pnlRibbon" could not be resolved in design time
Use this syntax:
<ResourceDictionary Source="projectName;component/Assets/Styles/Main.xaml" />
it been solved with add this code to the .csproj file
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>

MVVM Light ViewModelLocator + ResourceDictionaries

I originally posted this message on the MVVM Light CodePlex page but haven't heard a response yet so I'm hoping someone here can help me. Here is the question:
I recently started playing with MVVM (new to WPF too - quite the learning curve for all of this) and everything was working great with my ViewModelLocator instance and binding design-time for VS2010 until I started using the MetroToolkit provided on CodePlex. Before utilizing the toolkit, I had the following:
<Application.Resources>
<local:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</Application.Resources>
All of my views were binding great and everything looked really good. I was surprised at just how easy someone without MVVM (or MVC) experience could get up and running. Then I hit a snag of MetroToolkit requiring merged resource dictionaries and now no matter what I try I can't get VS to find my ViewModelLocator again inside App.xaml. Here is the new markup:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Colors.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Animations.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Geometry.xaml"/>
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Generic.xaml"/>
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Buttons.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Scrollbar.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Scrollviewer.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/RadioButton.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/ProgressBar.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/ContextMenu.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Tooltip.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Checkbox.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Headings.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Textbox.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Combobox.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Slider.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Expander.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/TabControl.xaml" />
</ResourceDictionary.MergedDictionaries>
<local:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</ResourceDictionary>
</Application.Resources>
I have tried giving the resource dictionary a key, adding the line outside of the area (above and below - throws nasty and very unhelpful errors) and can't get it to find my VM Locator. It works immediately when I remove the block from App.xaml, but based on my very limited knowledge of WPF I need those if I want the styles to be available to all views in my application.
Any thoughts? This has been driving me crazy for a few hours now.
yep...I just saw this the other day...You have to put a resource dictionary inside...
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Colors.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Animations.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Geometry.xaml"/>
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Generic.xaml"/>
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Buttons.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Scrollbar.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Scrollviewer.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/RadioButton.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/ProgressBar.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/ContextMenu.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Tooltip.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Checkbox.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Headings.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Textbox.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Combobox.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Slider.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Expander.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/TabControl.xaml" />
<ResourceDictionary>
<local:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
**EDIT
Sorry...Fixed it now...I was going from memory...this is the way it is in mine.
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionaries/converters.xaml" />
<ResourceDictionary Source="assets/styles.xaml" />
<ResourceDictionary Source="assets/sdkstyles.xaml" />
<ResourceDictionary Source="assets/corestyles.xaml" />
<ResourceDictionary>
<local:ApplicationResources x:Key="ApplicationResources" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Resources