Difference between DesignWidth and Width in UserControl in WPF

前端 未结 2 1781
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 20:02

When I create a new UserControl in WPF, studio creates some XAML:



        
相关标签:
2条回答
  • 2020-12-30 20:49

    d:DesignHeight and d.DesignWidth are for the Designer (the WYSIWYG), in Visual Studio or in Expression Blend. Height and Width are actually for runtime.

    0 讨论(0)
  • 2020-12-30 21:06

    Properties d:DesignHeight and d:DesignWidth="300" are used because (Source):

    • UserControls are not embedded in a parent view. Width and Height are not set.

    • Constructor of the root-element is not called. Root Element is replaced by the designer. ViewModel is not created.

    • Controls behave different. No mouse and keyboard events. Design time extensions loaded

    To improve the design experience, Microsoft provides special designtime attributes that can be added to any WPF element and serve as a hint for the design tool.

    All that is used in the prefix d: is used to design mode, these include properties such as:

    d:DesignWidth

    d:DesignHeight

    d:LayoutOverrides

    0 讨论(0)
提交回复
热议问题