日期:2014-05-17  浏览次数:21176 次

WPF,UserControl中的DesignWidth是什么意思?

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="WpfApplication1.UserControl1"
x:Name="UserControl"
d:DesignWidth="245.983" d:DesignHeight="161.023">
     <Grid>
       ....
       ....
     </Grid>
</UserControl>


UserControl中的DesignWidth和DesignHeight是什么意思?
如何让控件的内容紧贴Grid呢?

------解决方案--------------------
d:DesignWidth=640,d:DesignHeight=480,这二个标记在blend中特别有用

<UserControl x:Class="MsShowCase.NavItem"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 mc:Ignorable="d"
 Height="640" 
 Width="480" 
...

默认情况下,silverlight总会有一个固定的尺寸,要想让其自动扩展,很简单把Height="640",Width="480"删除即可(或设置成Auto),但是这样处理后,用blend再打开该xaml文件,可视区域就为0了,很不方便选取对象,这时我们可以加上这二个标识,


<UserControl x:Class="MsShowCase.NavItem"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 mc:Ignorable="d"
 Height="Auto" 
 Width="Auto"
 d:DesignWidth=640
 d:DesignHeight=480 
...

再用blend打开时,会发现可视区域变成640*480了,而运行时即仍然可以自动扩展

作者:菩提树下的杨过
出处:http://yjmyzz.cnblogs.com 
------解决方案--------------------
设计面板的大小,应该是让grid紧贴design吧,把,grid长和宽去掉就紧贴了