1

How do I configure WPF to make its controls use the sizes recommended by Microsoft?

For example, a button should be 23 pixels high, including a 1 pixel transparent border. How do I implement the transparent border? Button.BorderBrush controls the visible border.

Another example is a single-line text box, which should be 23 pixels high.

Do I have to style everything by hand? Or is there way to cause the controls to default to a native Windows user experience?


Update: Here's a visual of some of the differences.

WPF controls:

WPF controls

Standard Windows controls: (from the Common Item Dialog, e.g. in Notepad, clicking File > Open)

Common Item Dialog controls

This isn't a perfect comparison, since the in the Common Item Dialog, the file name box is a ComboBox, not a TextBox. I tried comparing the Print Setup and Print dialogs (also from Notepad), but they don't use the same size buttons or even the same font as the open file dialog. I keep forgetting that I'm dealing with Microsoft here, not Apple.

There is a distinction regarding the button that is consistent through all of Notepad's dialogs, which WPF doesn't match by default. If the button is a default button, the border is thicker in Notepad. The button's transparent border turns blue. For a Notepad non-default button, you can click one pixel outside the visible border and still hit the button. This doesn't work for the WPF button.

Flexibility is nice, but native it-just-works-and-looks-great controls would be really nice. If there's a drop-in solution where I don't have to think about this stuff, that would be great.

Here's the XAML for the WPF controls:

<StackPanel Name="controls" Margin="20">
    <TextBox Text="Default TextBox" />
    <TextBox Height="23" Text="TextBox with height 23" />
    <Button Content="Cancel" />
    <Button Height="21" Content="Cancel" IsDefault="True" />
</StackPanel>

And the code-behind:

foreach (Control control in controls.Children) {
    control.Margin = new Thickness(0, 10, 0, 10);
    control.VerticalContentAlignment = VerticalAlignment.Center;
}
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
  • there is a default style, not sure if it's windows standard and you can configure each type's default style in one place. I tend to do it in App.xaml – kenny Mar 25 '19 at 16:07
  • BorderBrush can be set to Transparent and BorderThickness to 1 pixel, but maybe I'm missing your point there. – kenny Mar 25 '19 at 16:13
  • 1
    @kenny The Windows guidelines calls for two borders: a visible border (built into the control), surrounded by an invisible border. As far as I can deduce, the invisible border is intended to provide a larger click area, while keeping buttons a couple pixels smaller to leave more space between controls for a less cluttered feel. `BorderBrush` sets the visible border. There's no property that I know of to work with the invisible border. – Edward Brey Mar 25 '19 at 16:17
  • Guess you're correct, they aren't windows standard. Maybe it's best to stick with Winforms. Someone already or even microsoft., perhaps built up a default set styles to make them so. The projects I've used WPF mostly tried look more stylish the what was the "old"standard windows "look". – kenny Mar 25 '19 at 23:27
  • What's wrong with the default styles? They are as "standard" as it gets. – mm8 Mar 26 '19 at 10:25
  • @mm8 I updated my question with examples and discussion of the non-standardness. – Edward Brey Mar 26 '19 at 12:52

0 Answers0