MaterialDesign Control Properties (ComboBox) - c#

I use MaterialDesign and I want to change the appearance of the popup window of a ComboBox.
I did a little research and then came across it here.
change combobox dropdown list background color wpf xaml
Miljac’s answer contains the key MaterialDesignPaper. Is there a documentation of these keys?
I am not being offered keys via IntelliSense.

There is no detailed documentation on the resource keys and where they are used. However, you can have a look at the GitHub repository Wiki. There is a page that lists all the brush names, but it does not provide any information beyond that.
If you want to know which control uses which brushes, you can check the control style list. Pick the control style that you use and it will take you to the XAML style files, where you can identify the used brushes, e.g. for ComboBox see line 548 where MaterialDesignPaper is referenced and the subsequent lines from 553 on where the popup background is bound.
IntelliSense is not reliable when it comes to resource dictionaries e.g. merged into the application resources and resources then being used in a custom view. These are limitations of IntelliSense, the resources may be perfectly available at runtime. The same applies to the designer, it may yield warnings that resources cannot be resolved, but in fact they are available at runtime.

Related

XAML/C#: Page/Property Style Changing Efficiency

I am currently working on a WPF project, and I am at an aspect of the program where I don't know how to create the solution efficiently.
Problem:
In my program, I plan on implementing UI versions (Dark mode, Light mode, etc.). Basically just UI color preferences. However, I am unsure of the best way in which I can use the other UI features.
So far, I have set up styles for each UI preferences in the APP.XAML, based on individual properties, such as textboxes and rectangles, and put the general style within the individual pages to be shown.
The UI changes need to be kept within the same SHOWN XAML file so that events can be implemented. I believe it needs to be done by using APP.XAML (which I have already been using this). However, what would be the best way in showing the UI changes? Should I be creating a whole page style? Changing each property individually based on styles? Or is there some better way in completing the UI changes efficiently.
Thanks!
In answer to some of the questions and statements:
The standard templates (see: https://stackoverflow.com/a/45603437/563088) use Themes so that would be a logical first step to follow
It might be easier to maintain separate files with the templates and colors in resource dictionaries although templates will have to be in the Generic.xaml
Do not use events, use Commands and Bindings. If you need to use events, do not hook them up in XAML but hook them up in the OnApplyTemplate of the controls. That way templates can be swapped out and templates are no longer forced to provide specific controls/events as the OnApplyTemplate can search for a control and skip it if it isn't found.
As for switching: from experience I found it easier to define multiple color/brush/resource sets in separate files. Give these colors and brushes the same names (e.g. HighlightBrush, ButtonBorder or CheckBoxCheckGlyph). Depending on the theme you load a different resources file. the templates would simply refer to these resource names (using DynamicResource if you want to enable live switching or StaticResource for switching on restart of the window/app)

Templated Control vs Custom Control in UWP. No clear answer found online

In my UWP app, my control options are User Control and Templated Control. My understanding of a User Control is KIND OF clear at this point.
I was told that a Custom Control's style/template is only instantiated in memory once, and that this only happens at the time the control is first used. That's what I want since I know the control I am creating will be used in a ListView.
In the book, XAML Unleashed, however, the author creates his Custom Control by starting with a User Control, and then simply changing it's base class. The thing is that the control he created calls InitializeComponent(). I hear that this type of class uses more memory because it is re-instatiated for each item in the ListView.
Also, I never thought that Custom Controls used the InitializeComponent() method. I thought there was simply a call to this.DefaultStyleKey = typeof(MyClass); in the constructor. What gives? I am confused on what is what...
And last, why is the style/template of the Templated Control placed in the global Generic.xaml file, instead of its own separate file (i.e., xaml file and a code-behind file pair)? If the control is supposed to be custom and "portable", then shouldn't it be totally separate from other code? I haven't found a single article explains any of these things in detail on any level.
This is something most people get wrong so I'll try to clarify a few things for you.
Memory
The whole memory thing, it's all in the Visual Tree. When you instantiate any control, whether templated or UserControl, you will use up memory with every instance because in both cases you are creating a full copy of the visual components in the template.
The templated control will create a copy from the ControlTemplate while the UserControl parses the XAML file when InitializeComponent() is called.
Memory usage will be the same if you create 100 templated controls or 100 user controls if their content is the same.
Usage
Templated controls are best for situations where you're creating a single component, like a Button, Slider, MyStarRatingInput, etc. and you're giving the users of your control the ability to swap out the template with their own. It takes a lot more effort to do this properly than UserControls because the logic has to be template agnostic and your templates have to react properly with visual state changes.
A UserControl is best for layout or views, like forms, popups, screens, pages, etc. You will not give someone the freedom to tamper with the content of your view. You may expose a few public/dependency properties if some views are reusable in a small way, but generally they are set in stone.
Generic.xaml
I honestly don't have an answer for this. Microsoft should've allowed multiple resource dictionaries to enable cleaner partitioning of control templates. Generic.xaml is a reserved filename that referencing projects will look for as the root source of the base styles of your controls. You could reference other XAML files from Generic.xaml, but that's annoying and it bloats the root of your resource dictionary. For now, you're stuck with this method.
Recommendation
If you're sharing a control library, you would want to use templated controls as much as possible. If you're building controls, views, pages, etc for your current project and they're not meant for reuse, then use UserControls.
You can still create a UserControl in your control library if you plan on owning the template and forcing all users to accept your design.
I also recommend templated controls for items that you plan on instantiating a hundred times in a single view, like a ListView. You will see noticeable speed improvement if your template is preloaded into memory instead of parsing a XAML file on every instance.

How/Where to Find Microsoft Default Styles for WPF Controls

I am looking to change the style of a control but I basically want to copy part of a default style. Does anyone know how I can figure out what the default style of a control is?
In my case I am wanting to make the column headers in a DataGrid go blue on mouse over like the row headers do.
You can find some templates that are very close to the defaults on this MSDN site
Another alternative is to get a copy of Expression Blend and use it to make a copy of the default style, however Blend isn't free
Contrary to what Rachel says, the link she provides does not provide the default templates.
I have seen using System.Windows.Markup.XamlWriter.Save(myObject.Template) that the default templates are completely different from what that site shows.

Styling Silverlight Telerik AppointmentDialogWindow

So I am using Silverlight telerik RadScheduler. When creating an appointment using this control an AppointmentDialogWindow pops up. Now, I want to change the look of the window (i.e. its borders, frame etc.)
I am pretty good with Blend but I guess some code - behind will be necessary to set the window style for this Dialog Window.
Any Suggestions?
If you have the full source, go the the specific Theme folder you are looking to implement and grab the SchedulerView.xaml file from there. This is the style file for that specific control.
Reference this resource as a ResourceDictionary in App.xaml or the respective page you will implement the control.
Now when you edit this style sheet it will directly affect how the SchedulerView control operates, including it's child windows.
Warning: this is a cumbersome pain in the neck. Telerik doesn't really like people messing with their styles, and they have acknowledged that they do no typically make it easy for their existing styles to be modified.
Here is how to implement a custom theme:
http://www.telerik.com/help/silverlight/common-styling-apperance-themes-custom-theme-project-telerik-approach.html

How To Track Down Silverlight Style and Template Issues

I have a very large silverlight application. I am using a telerik RadGridView control.
I noticed that the header style of the RadGridView is not the standard header as given out of the box by telerik. I.e. the colours are different and the text is different etc.
I first tried to define my own styles and templates (which work in a test project). They are ignored by the RadGridView.
So I started hunting around our application to find out whether a template or style has been applied to make the header different. I couldn't find it.
Are there tools out there that can show me what templates / styles are applied to a particular control and where they come from? A way to debug it in effect.
I am using silverlight spy, but the free edition doesn't show me everything I need.
UPDATE:
I can see what is happening here, a theme is being applied like this,
Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.Windows7Theme();
So the theme must be overiding any template and styles changes that I apply.

Categories