WPF:如何在对话框单位中指定单位? [英] WPF: How to specify units in Dialog Units?

查看:90
本文介绍了WPF:如何在对话框单位中指定单位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出如何使用适当的对话框单元(DLU)在WPF中布置简单对话框的方法。







什么是对话框单元?



对话框是基于用户首选字体大小的度量单位。
定义一个对话框单元,使平均字符为4个对话框
单元宽乘以8个对话框单元高:





这意味着该对话框单位:




  • 使用所选字体更改

  • 更改为所选DPI设置

  • 不是正方形







我花了大约两个小时来确定Windows Vista中带有各种 dlu 测量值的示例对话框的尺寸。有人可以提供生成此对话框的相应XAML标记吗?





图片链接



现在我当然知道WPF XAML几乎没有。每次开始时,我都会受阻,因为我无法弄清楚如何放置任何控件。似乎WPF中的所有内容都必须包含在某种类型的面板中。有StackPanels,FlowPanels,DockPanel,网格等等。如果您没有这些,那么它将无法编译。



我唯一能提出的XAML(使用XAMLPad)到目前为止:

 < DockPanel xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation  
xmlns:x = http://schemas.microsoft.com/winfx/2006/xaml>
< Image Width = 23 />
< Label>确定要将此文件移到回收站吗?< / Label>
<图片宽度= 60 />
< Label> 117__6.jpg< / Label>
< Label>类型:ACDSee JPG Image< / Label>
< Label>评级:未分级< / Label>
< Label>尺寸:1072×712< / Label>
< Button Content = Yes Width = 50 Height = 14 />
<按钮Content = Cancel Width = 50 Height = 14 />
< / DockPanel>

哪个呈现为华丽的怪兽。没有控件放置或调整大小。我无法弄清楚如何在窗口中放置控件,也无法正确调整控件的大小。



有人可以将屏幕截图转换为XAML吗?



注意:您不允许测量屏幕截图。所有对话框单元(dlu)的宽度和高度都已指定。



注意: 1个水平DLU!= 1个垂直DLU。水平和垂直DLU的大小不同。






另请参见





凹凸: 2011年6月20日

解决方案

以下XAML将为您提供所需的效果。



请注意,我已将标记中的DLU单位加倍-从而保持了相同的方面。 Button高度为14个单位时看起来很有趣。您可能需要修改市场上显示的数字。



此外,我开始将一些 Vista布局删除为单独的样式。您也许可以沿着这条道路继续前进,因此您可以遵循Vista指南,拥有一组可重用的样式。我相当确定其他人也做了类似的事情。



此外,我对对话框的大小有所保留。您提到要210x96个单位-您需要设置此金额以及窗口镶边。



无论如何,内容如下:

 < Window x:Class = VistaLayout.Dialog 
xmlns = http://schemas.microsoft.com/winfx/2006/xaml/演示文稿
xmlns:x = http://schemas.microsoft.com/winfx/2006/xaml
标题=删除文件
ResizeMode = NoResize
Height = 212 Width = 430>
< Window.Resources>
< Style x:Key = FooterButtonStyle TargetType = {x:Type Button}>
< Setter Property = Width Value = 100 />
< Setter Property = Height Value = 28 />
< Setter Property = Margin Value = 8,0,0,0 />
< / Style>
< Style x:Key = FooterPanelStyle TargetType = {x:Type UniformGrid}>
< Style.Resources>
< Style TargetType = {x:Type Button} BasedOn = {StaticResource FooterButtonStyle} />
< /Style.Resources>
< Setter Property = Rows Value = 1 />
< Setter Property = Horizo​​ntalAlignment Value = Right />
< / Style>
< /Window.Resources>
< DockPanel Margin = 14>
< ;!-页脚->
< UniformGrid DockPanel.Dock =底部
Style = {StaticResource FooterPanelStyle}>
< Button> _Yes< / Button>
< Button> _No< / Button>
< / UniformGrid>

< ;!-主要内容->
< Grid>
< Grid.ColumnDefinitions>
< ColumnDefinition Width = Auto />
< ColumnDefinition Width = 8 />
< ColumnDefinition Width = Auto />
< /Grid.ColumnDefinitions>

<图片宽度= 64 />

< StackPanel Grid.Column = 2>
< TextBlock Margin = 0,6,0,14>确定要将此文件移到回收站吗?< / TextBlock>

< Grid>
< Grid.ColumnDefinitions>
< ColumnDefinition Width = Auto />
< ColumnDefinition Width = 14 />
< ColumnDefinition Width = Auto />
< /Grid.ColumnDefinitions>

<图片宽度= 60 />

< StackPanel Grid.Column = 2>
< TextBlock> 117__6.jpg< / TextBlock>
< TextBlock>类型:ACDSee JPG图片< / TextBlock>
< TextBlock>评级:未分级< / TextBlock>
< TextBlock>尺寸:1072×712< / TextBlock>
< / StackPanel>

< / Grid>

< / StackPanel>

< / Grid>

< / DockPanel>
< / Window>与大多数XAML一样,这可以通过多种方式完成-这只是一种解决方案。



希望这会有所帮助!


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


What's a dialog unit?

A dialog is a unit of measure based on the user's preferred font size. A dialog unit is defined such that the average character is 4 dialog units wide by 8 dialog units high:

This means that dialog units:

  • change with selected font
  • changed with selected DPI setting
  • are not square


i spent about two hours dimensioning this sample dialog box from Windows Vista with the various dlu measurements. Can someone please give the corresponding XAML markup that generates this dialog box?

(Image Link)

Now admittedly i know almost nothing about WPF XAML. Every time i start, i get stymied because i cannot figure out how to place any control. It seems that everything in WPF must be contained on a panel of some kind. There's StackPanels, FlowPanels, DockPanel, Grid, etc. If you don't have one of these then it won't compile.

The only XAML i've been able to come up with (uing XAMLPad) so far:

<DockPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Image Width="23" />
    <Label>Are you sure you want to move this file to the Recycle Bin?</Label>
    <Image Width="60" />
    <Label>117__6.jpg</Label>
    <Label>Type: ACDSee JPG Image</Label>
    <Label>Rating: Unrated</Label>
    <Label>Dimensions: 1072 × 712</Label>
    <Button Content="Yes" Width="50" Height="14"/>  
    <Button Content="Cancel" Width="50" Height="14"/>  
</DockPanel>

Which renders as a gaudy monstrosity. None of the controls are placed or sized right. i cannot figure out how to position controls in a window, nor size them properly.

Can someone turn that screenshot into XAML?

Note: You're not allowed to measure the screenshot. All the Dialog Unit (dlu) widths and heights are specified.

Note: 1 horizontal DLU != 1 vertical DLU. Horizontal and vertical DLUs are different sizes.


See also

Bump: 6/20/2011

解决方案

The following XAML will give you the effect you are looking for.

Note that I have doubled the DLU units in the markup - thus keeping the same aspect. It looked funny having a Button height of 14units. You may need to tinker with the figures presented in the market.

Also, I started to remove some of the "Vista Layout" into separate styles. You may be able to continue down this path so you have quite a reusable set of styles which follow the Vista guidelines. I'm fairly sure some other people have done something similar.

Furthermore, I took some liberties with the size of the dialog. You mentioned you wanted 210x96units - you would need to set this amount, plus the window chrome.

Anyway, on with the content:

  <Window x:Class="VistaLayout.Dialog"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Delete File" 
      ResizeMode="NoResize"
      Height="212" Width="430">
    <Window.Resources>
      <Style x:Key="FooterButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Width" Value="100" />
        <Setter Property="Height" Value="28" />
        <Setter Property="Margin" Value="8,0,0,0" />
      </Style>
      <Style x:Key="FooterPanelStyle" TargetType="{x:Type UniformGrid}">
        <Style.Resources>
          <Style TargetType="{x:Type Button}" BasedOn="{StaticResource FooterButtonStyle}" />
        </Style.Resources>
        <Setter Property="Rows" Value="1" />
        <Setter Property="HorizontalAlignment" Value="Right" />
      </Style>
    </Window.Resources>
    <DockPanel Margin="14">
      <!-- Footer -->
      <UniformGrid DockPanel.Dock="Bottom" 
                       Style="{StaticResource FooterPanelStyle}">
        <Button>_Yes</Button>
        <Button>_No</Button>
      </UniformGrid>

      <!-- Main Content -->
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition Width="8" />
          <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <Image Width="64" />

        <StackPanel Grid.Column="2">
          <TextBlock Margin="0,6,0,14">Are you sure you want to move this file to the Recycle Bin?</TextBlock>

          <Grid>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="14" />
              <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Image Width="60" />

            <StackPanel Grid.Column="2">
              <TextBlock>117__6.jpg</TextBlock>
              <TextBlock>Type: ACDSee JPG Image</TextBlock>
              <TextBlock>Rating: Unrated</TextBlock>
              <TextBlock>Dimensions: 1072 × 712</TextBlock>
            </StackPanel>

          </Grid>

        </StackPanel>

      </Grid>

    </DockPanel>
  </Window>

As with most XAML, this could be done in a myriad of ways - this is only one solution.

Hope this helps!

这篇关于WPF:如何在对话框单位中指定单位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆