WPF Control Templating: Keeping Windows look and feel - c#

I'm working on a control template for an inherited TextBox class. I'd like to use this template to add additional controls with the ScrollViewer. I can achieve that goal just fine, what I can't do recreate the border in such away that it matches the Windows look and feel.
I have Windows Classic as my theme on XP. Textboxes are typically shown with the standard inset border style. With the XP Fischer Price theme, borders of textbox are a flat style and light blue.
Is there any way of specifying something like this in the template? Ideally it would use the theme default (grey inset for Classic, flat and light blue for fischer price theme).

You will have to provide a separate ControlTemplate for each known theme. There is no generic way to create a theme-agnostic ControlTemplate. Infact WPF itself maintains separate ControlTemplates for each official theme (excpet the Zune theme, where WPF falls back to battleship gray).

I'm not sure if this will work as I am not sure what your setup is. I also don't know if you are concerned about changing themes on the fly. You can try to set the style for your text box class to have
BasedOn="{DynamicResource {x:Type TextBox}}"

Related

Button Styles via xaml and expression blend

I created a custom control that looks a lot like the tab buttons in VS 2012. In my control I could set a propertiy to posistion the text and sidebar vertical or horizontal. After playing around with the control I figured there was probably a better way to go about this. So i fired up the Expression Blend preview and suprising enough (only second or third time using blend) was able to create a style to achieve a simliar style button. However, Now I want to have control over the text and sidebar being vertical or horizontal. I would also like to have control over the mouse over color. Is this possible to do via one style or am i going to have to create a bunch of different styles?
If I understood correctly you can achieve what you want to do with event triggers.

Customizing Windows Forms (table)

I have no clue if this is possible or not as I'm new to C#. But is it possible to make a Windows Forms look like the picture? Where you have a
gradient at top
alternating color rows
change the default text color
change the default highlight color
change the way the scroll bar looks
If so, are there tutorials for these someone can point me to?
Gradient effects will take tedious paint task. You have some example here
Alternating Row Colors,
datagridview1.AlternatingRowsDefaultCellStyle.BackColor= Color.Blue;
Change Text Color
datagridview1.RowsDefaultCellStyle.ForeColor = Color.Red;
Change Highlight Color
`datagridview1.RowsDefaultCellStyle.SelectionBackColor = Color.Pink;
As far as I know scroll-bar will have the look of your current system theme and cant be change that easily unless you write your own code for it.
Regarding skinning (gradients, custom scroll bar): WinForms are a wrapper around Win32 native controls. They were not designed with visual appearance customization in mind. It is possible but will require an awful lot of work: There is nothing comparable to CSS in WinForms.
An arguably easier alternative would be WPF.
Of course, the most straightforward might be to look for a 3rd party component such as Krypton's DataGrid (free).

How do you change the color of the WPF treeview arrow?

How would I go about changing the color of the arrows that show up next to a treeviewitem in the wpf treeview? The arrows indicate whether the item is expanded or collapsed, I believe they are plus / minus signs with the windows xp theme.
This is embedded into the template, you could only change the color by copying the default Aero-Style for the control and changing the hard-coded value, or by drilling down the visual tree on-load to change it that way.
To get the default style & tenmplate see MSDN (Default WPF Themes link).
If you have MS Blend, you can achieve this by creating your own template.
Here is an example:
http://geekswithblogs.net/tkokke/archive/2009/06/29/styling-a-treeview-in-silverlight-and-blend-3.aspx

Active TabPage has same color as my controls

I have made a TabControl and want to use some controls (labels, textboxes, buttons and combobox drop-downs). The problem is that when I select a tab, the default background color is not the same as the default background color of the form the controls used to be on. The color of the tab and the controls are too similar and it doesn't look good.
I have looked, but people seem to say that it's impossible to color tabs. What is a good solution to this? Should I put some kind of frame, label or something else inside the tab to make the background darker?
It's easy to get your tab pages to use the same background color as your form:
Make sure that the TabPage you want to change is visible in the designer. Click on it to select it.
In the Properties Window, find the UseVisualStyleBackColor property, and set it to False.
And as a bonus, once you've set this property to False, you can specify any background color that you want for the TabPage using its BackColor property.
The reason that this works is that you're forcing the tab page not to render with visual styles (i.e., themes as defined by Windows). The default theme actually paints tab pages a slightly lighter shade of the color used to paint other 3D elements (like forms and buttons). The problem (under the Aero theme in particular) is that the color of the standard 3D elements is so light already that the tab pages almost look white!
If you're satisfied with the contrast of the controls against the standard background color of your form, I suggest that you simply set the UseVisualStyleBackColor property to False and leave it at that without specifying a custom background color. Respecting the user's default theme is generally the best practice, rather than trying to skin an application yourself.
EDIT: Note that this will not change the color of the tabs themselves at the top of the TabControl. To do that, you're going to have to specify it as owner-drawn and handle its DrawItem event, forcing you to do all of the painting yourself. In most cases, however, this is not necessary.

Problems with .net and toolbar, menu & status bar rendermode (blue) and standard form (grey)

Hiya,
I'm a bit of a newbie to .NET so please ignore my ignorance. If you look at the above image (a complete prototype, ignore black bits :)) you will see lovely menus, toolbars & statusbars all using windows XP render mode and in a funky blue.
Look at the form, labels, checkboxes and other buttons and you see horrible old school windows grey. These components don't have a render mode.
My question: is there any way to show everything in XP style or do I have to chose new components?
Thx.
A.
It looks like XP style. The button has rounded corners with smooth 3D look (not just "raised box" as the "old school gray" was like).
Here is example of old style grey buttons:
(source: techmynd.com)
It seems like there are no way of getting the toolbar background as background on the checkbox and button. An alternative is to add them as toolbar buttons instead, using DisplayStyle=Text.
The check box can be replaced with a toolbar button and setting CheckOnClick=True. It also has a property Checked that can be true or false. If you need tri-state, you can use the property CheckState instead.
This is already standard XP style.
Try changing the render mode of the Toolstrip; that may make you happier.
Otherwise, you'll need to move to a third-party component vendor.
I've been using DevExpress, and I'm very happy with them.

Categories

Resources