I am creating a popup dialog using microsoft's WPF.
The thing is that this popup must support two or more different styles, for instance, depending on how it is called the popup must have a red background and white text in the foreground, or it must have a white background and gray text in the foreground.
What I would like to do is create as many styles as necessary in my xaml file and just choose each of them depending on how the popup was created, therefore I would like to know if it is possible to create something like this (kind of a dynamically applied style) inside the .xaml file, or if it is better to just do this programatically in the code behind.
Also please note that I am using the Visual Studio 2010 with the .NET Framework 4.0.
Thanks,
Felipe
I would define an enumeration that names the styles, then either use DataTriggers to set the style on the control from a wrapping border.
Related
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)
Is it possible to remove the border of a standard C# Button ? I know that I could set the FlatStyle property to Flat and customize the FlatAppearance property to hide the border but I would prefer to use the Standard property to ensure that the control appears under all operating systems like a default Button. Did you have any suggestions how I can solve this issue? I am working with a Windows Forms Application.
You could use an image and make it clickable, that is one way to avoid the borders, but there are several options. Good luck!
If you are using windows forms and trying to implement Flat UI, Material UI, Metro-Looking controls, you're in hell. It is has limited properties for customizations unless you know how to work with Graphics and Animation. You'll have to use imagebox or picture box and dynamically change its image on different events.
I'll suggest WPF or Windows Presentation Foundation for a more customizable User Interface.
I have a style Xaml which I use for styling my WPF windows. But the same style won't get applied for the FolderBrowseDialog which I use in my windows. This gives a weird UI difference between the actual windows and the dialog pop-ups. How to get this corrected?
As far as I know unfortunately you cannot. Either you have to create your own user control or use some of the already defined in the internet.
One cool with a lot of other fancy controls is in Kevin Moore's Bag-o-Tricks.
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
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.