【问题标题】:Difference between DesignWidth and Width in UserControl in WPFWPF中UserControl中DesignWidth和Width的区别
【发布时间】:2014-03-19 05:29:27
【问题描述】:

当我在 WPF 中创建一个新的UserControl 时,工作室会创建一些 XAML:

<UserControl x:Class="MOG.Objects.Date.Calender"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <Grid>

    </Grid>
</UserControl>

UserContol我也可以添加Width属性。 DesignWidthWidth 有什么区别?

【问题讨论】:

    标签: c# wpf xaml user-controls


    【解决方案1】:

    d:DesignHeightd.DesignWidth 用于 Visual Studio 或 Expression Blend 中的设计器(所见即所得)。 HeightWidth 实际上是用于运行时的。

    【讨论】:

    • 这个答案简单明了。接受的答案中有太多不需要的信息
    【解决方案2】:

    使用属性 d:DesignHeightd:DesignWidth="300" 是因为 (Source):

    • 用户控件未嵌入到父视图中。 WidthHeight 未设置。

    • 不调用根元素的构造函数。根元素被设计者替换。未创建 ViewModel。

    • 控件的行为不同。没有鼠标和键盘事件。 已加载设计时扩展

    为改善设计体验,Microsoft 提供了可添加到任何 WPF 元素并作为设计工具提示的特殊设计时属性。

    前缀d:中使用的所有内容都用于设计模式,包括以下属性:

    d:DesignWidth

    d:DesignHeight

    d:LayoutOverrides

    【讨论】:

      猜你喜欢
      • 2010-10-11
      • 2011-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-14
      • 2022-08-14
      相关资源
      最近更新 更多