-
Notifications
You must be signed in to change notification settings - Fork 3.4k
FAQ
For control specific questions look at the corresponding pages under the Controls section in the sidebar.
This error typically comes when you have a static resource referencing one of the material design styles, and have not included the appropriate resource dictionary that contains the style. Try the following:
- Ensure that you have loaded all of the default material design styles in your App.xaml. You can find directions for this in the Getting Started guide.
- Ensure you have referenced the control specific resource dictionary that contains the style. The path for this is resource dictionary should be
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.<Control Name Here>.xaml" />
. For example, if you were trying to reference theMaterialDesignFloatingActionMiniButton
style for a button, the resource dictionary source would be:<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml" />
. Typically these inclusions are done at root of your Window, User Control, or Template. You can find the full list of the resource dictionaries here
Project fails to build with error: The command ""...\MaterialDesignInXamlToolkit.paket\paket.exe" restore --references-file "...\MaterialDesignInXamlToolkit\MainDemo.Wpf\paket.references"" exited with code 1.
This error typically occurs when changing branches or occasionally on the initial build. Simply restart Visual Studio and rebuild the project.
This can also occur if your project has been cloned at too deep of a path. Try moving the repository closer to the root (typically C:\) and try again.
This occurs when you replace a style rather than extending from it. In the same way that C# classes can inherit from another class a WPF Style can also extend another Style. In many cases, if you are not explicitly setting the style, you can simply use the default style for the control as the base. For example, this creates a new style for Button
that extends the default style being applied to Buttons
.
<Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
<!-- Your setters and triggers here -->
</Style>
You can also specify an explicit style to derive from. For example, this style extends the existing MaterialDesignFlatButton
style. This also requires that you have included the appropriate resource dictionary that contains the style you want to reference.
<!--Ensure you have referenced pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml-->
<Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}">
<!-- Your setters and triggers here -->
</Style>
This error occurs when you have copied some of the example Binding validation rules that exist in the demo app. These validators are merely one simple way of doing data validation in WPF. These validators are part of the demo app and not part of the Material Design in XAML library. If you would like to use them in your app, you are welcome to copy the code into your project and adjust the namespace to match.
You should not need this control inside of your application. This control was designed to make it easy for people to be able to see the corresponding XAML at run-time inside of the demo application. So when you copy the code out of the demo application, you can omit this control.
In WPF there exists the concept of an Attached Property. These properties can be specified on any object. Common ones you have likely uses are DockPanel.Dock
, Grid.Row
, or Grid.Column
. To see these in C# code you simply invoke them as static methods. For example if you want to set materialDesign:ElevationAssist.Elevation="Dp1"
in C# you should do:
FrameworkElement myControl = ...;
ElevationAssist.SetElevation(myControl, Elevation.Dp1);
When Using MahApps, attempting to reference PopupEx has the error "The type 'PopupEx' exists in both 'MaterialDesignThemes.Wpf' and 'ControlzEx`".
This occurs because we include the same PopupEx code file in the MaterialDesginTemes.Wpf project that is also included in ControlzEx (which is referenced by MahApps). In most cases, types can be identified by simply specifying their full type name (namespace and type name), however in this case those match, and the types must be delimited by their assembly. In C# this is done using the extern alias. This allows you to give an alias to one of the assemblies so that you can specify which class you intend to use. Though support for applying extern alias
is coming soon to NuGet see issue 4989, at present the simplest solution is to include an MSBuild target that will apply the alias to one of the assemblies. This target can be included anywhere inside of the <Project>
element of your .csproj
file.
<Target Name="ChangeAliasesOfNugetRefs" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'ControlzEx'">
<Aliases>controlzEx</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
Then in your C# files:
//extern alias must come before any using statements
extern alias controlzEx;
...
//A reference to the PopupEx class inside of ControlzEx
controlzEx::ControlzEx.PopupEx popup = ...
//Because no alias is specified on MaterialDesignThemes this reference now refers to the type in that assembly
ControlzEx.PopupEx popup2 = ...
Or in XAML
xmlns:mdix="clr-namespace:ControlzEx;assembly=MaterialDesignThemes.Wpf"
xmlns:controlzEx="clr-namespace:ControlzEx;assembly=ControlzEx"
...
<mdix:PopupEx />
<controlzEx:PopupEx />
This is normal WPF commanding behavior. When you attached a command to a button, the command can indicate if it is able to execute. If it is not able to be executed, the button is then disabled. Within WPF there are two common types of commands that get used.
- The first type is a simple
ICommand
implementation that is provided via a view model (or similar). These command often simply invoke a method when they are executed. Though WPF does not provide a native implementation for this, many popular MVVM libraries do have some implementation of theICommand
interface that is designed to make method invocation simple. - Routed commands, are setup to explicitly cause a separation between the element invoking the command, and the element handling the execution of the command. When a routed command is invoked, WPF looks up through the visual tree (starting with element that invoked the command) for an element that can handle the command. If no handler is found, then the command will cause the button to be disabled. In the case with the
DialogHost.OpenDialogCommand
this often occurs because noDialogHost
instance is found in the visual tree. You can also specify and alternate command target to use to find the handler for the RoutedCommand by using the CommandTarget property. For a longer explanation see Understanding Routed Commands.
If you see any mistake or want to contribute to this wiki feel free.
Home
Contributing
Compiling From Source
Glossary
Getting Started with MDIX
Getting Started
Tutorial On YouTube (português-BR)
Frequently Asked Questions
Examples Repository
Release Notes
Pack Icon Changes
2.0.0 Breaking Changes
Controls
All Control Styles
Buttons
ComboBox
Dialogs
PopupBox
Snackbar
TextBox
Toggle Button
Transitions
Icons
Theming
Advanced Theming
Brush Names
Custom Palette Hues
Fonts
Overriding Material Design Styles
Swatches and Recommended Colors
Miscellaneous
MahApps Integration
Performance
Strong Naming
.NET 4.0 Compatibility
Projects using Material Design
Understanding Routed Commands