silverlight中的几个冷门标记 {x:Null},d:DesignWidth,d:DesignHeight

时间:2022-04-23
本文章向大家介绍silverlight中的几个冷门标记 {x:Null},d:DesignWidth,d:DesignHeight,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

{x:Null}:用于设置某属性值为Null,比如<Rectangle Fill="{x:Null}" />,其实就相当于<Rectangle />,个人感觉这个纯属MS的多余设计

另外要注意一个问题:

<Rectangle x:Name="rect" Stroke="Black" Width="90" Height="90"
 MouseLeftButtonUp="Rectangle_MouseLeftButtonUp" StrokeThickness="10" />

运行时,如果点击矩形中间区域,会发现无法触发Rectangle_MouseLeftButtonUp事件,因为矩形Fill属性为null,没有填充,相当于透明,所以鼠标点击穿透矩形,点到下面的东西上去了

解决办法:设置Fill="#00000000" 即设置一个完全透明的颜色

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了,而运行时即仍然可以自动扩展