WPF UserControl Design Time Size

后端 未结 9 856
[愿得一人]
[愿得一人] 2020-11-30 22:36

When creating a UserControl in WPF, I find it convenient to give it some arbitrary Height and Width values so that I can view my changes in the Visual Studio designer. When

9条回答
  •  失恋的感觉
    2020-11-30 23:00

    Some have suggested using the LicenseManager.UsageMode property which I've never seen before but I have used the following code.

    if(!DesignerProperties.GetIsInDesignMode(this))
    {
        this.Width = double.NaN;
        this.Height = double.NaN;
    }
    

    esskar,

    I just want to add that you should generally always call the method of the base when overriding an "On" method.

    protected override void OnVisualParentChanged(DependencyObject oldParent)
    {
        base.OnVisualParentChanged(oldParent);
    
        ...
    }
    

    Great workaround by the way, I'm using it myself now too.

提交回复
热议问题