Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
713 views
in Technique[技术] by (71.8m points)

user interface - How to specify units in Dialog Units in WPF?

i'm trying to figure out how to layout a simple dialog in WPF using the proper dialog units (DLUs).

i've come up with a simpler example, that cuts straight to the problem:

enter image description here

You can check the Windows UX Guidelines to see where these measurements come from.
The short version is:

  • dlu = dialog unit
  • dlu is based on the font size (items change with user's font size)
  • a horizontal dlu is different from a vertical dlu (dlu's are not square)

This comes from the definition of a dialog unit: the average character is 8dlus high by 4dlus wide.

Georgia 14pt:

enter image description here

If you use a smaller font (i.e. 8pt Tahoma verses 14pt Georgia), the dlus get smaller:

Segoe UI 9pt:

enter image description here

Note: You'll notice that resolution (i.e. dpi) has no impact on the discussion.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could try creating a Converter which returns the value multiplied by whatever your DLU is

For example, I created a MathConverter (code is here) which would let you specify something like

<Button Height="{Binding Source={x:Static local:Settings.VerticalDLU,
            Converter={StaticResource MathConverter},
            ConverterParameter=@VALUE*14}"

        Width="{Binding Source={x:Static local:Settings.HorizontalDLU,
            Converter={StaticResource MathConverter},
            ConverterParameter=@VALUE*50}" />

To make it easier to write and read, you can create a class that inherits from Binding and setup a default binding properties so all you have to do is

<Button Height="{local:MyVDluBinding Source=14}"
        Width="{local:MyHDluBinding Source=50}" />

I've never tried overwriting a binding with defaults for Converter and ConverterParameter, but I have overwritten a binding for validation purposes so I believe it's possible.

The ValidationBinding I created could be used like Text="{local:ValidationBinding MyProperty}" and automatically set ValidatesOnDataError=True, ValidatesOnException=True, UpdateSourceTarget=PropertyChanged in the bindings.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...