【问题标题】:Setting Design Time Size for Custom Control设置自定义控件的设计时间大小
【发布时间】:2013-09-03 03:02:11
【问题描述】:

如何设置自定义控件的设计时宽度和高度?
我创建了一个自定义 ItemsControl,即(generic.xaml 的内容)

<Style TargetType="{x:Type MyItemsControl}"   >
    <Setter Property="Height" Value="24" />
    <Setter Property="Width" Value="160" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:MyItemsControl}" >
                <Grid>
                  ...
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>     
  ...
</Style>

而且它工作得很好,但是如果我将控件从工具箱拖到我的窗口上,我的控件的默认大小是:高度 = 100 和宽度 = 200。我如何设置设计时大小,以便当我将控件从工具箱拖到窗口默认大小分别是24和160?

【问题讨论】:

    标签: c# wpf visual-studio-2010


    【解决方案1】:

    希望对你有帮助.......

    首先你必须通过继承它来制作你自己的控件 原始控件并设置 Hieght、width 以及您想要的任何内容 自定义控件……之后当你拖动你自己制作的控件时 将工具箱设置为您的表单,它将按照您的方式设置您想要的任何内容.......

    【讨论】:

      【解决方案2】:

      这是 Visual Studio 本身的一个设置,似乎没有办法改变它,微软也不打算改变它。

      来源:A user reported this issue to Microsoft online and a Microsoft employee responded and marked the issue as "Won't Fix".

      【讨论】:

        猜你喜欢
        • 2013-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-03
        • 1970-01-01
        相关资源
        最近更新 更多