silverlight:Silverlight 2 手把手(的 4) 创建 Silverlight 2 Control控件

  本文举例源代码或素材下载

  Silverlight 2 拥有更多Control控件支持你也可以自己定义Control控件引用到你项目中

  在 Silverlight 现有Control控件中并没有正圆这样个Control控件下面就如何实现个正圆Control控件步骤做下简单描述具体信息你可以参考后面参考代码获得:

  1. 首先在项目中添加新 Item:

Silverlight 2 手把手(的 4) 创建 Silverlight 2 Control控件

  2. 在 x:Class="Control.Circle" 中置入现有椭圆Control控件:

  1: <Grid x:Name="LayoutRoot" Background="White">
  2:    <Ellipse x:Name="myEll"></Ellipse>
  3:  </Grid>


  3. 定义正圆半径和填充颜色值:

  1: public Double Radius
  2:     {
  3:       get
  4:       {
  5:         myEll.Height /2 ;
  6:       }
  7:      
  8:       {
  9:         myEll.Height = value * 2;
 10:         myEll.Width = value * 2;
 11:       }
 12:     }
 13:     public SolidColorBrush Fill
 14:     {
 15:       get
 16:       {
 17:         (SolidColorBrush)myEll.Fill;
 18:       }
 19:      
 20:       {
 21:         myEll.Fill = (SolidColorBrush)value;
 22:       }
 23:     }


  4. 使用clr- 定义Control控件命名空间:

  1: xmlns:lm="clr-:Control"

  5. 使用Control控件

  1: <UserControl x:Class="Control.Page"
  2:   xmlns="http://schemas.microsoft.com/client/2007"
  3:   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4:   xmlns:lm="clr-:Control"
  5:   Width="400" Height="300">
  6:   <Grid x:Name="LayoutRoot" Background="White">
  7:     <lm:Circle Radius="40" Fill="black"></lm:Circle>
  8:   </Grid>
  9: </UserControl>


Silverlight 2 手把手(的 4) 创建 Silverlight 2 Control控件

  注:本文主要参考了 Laurence Moroney 先生在 MIX08 期间图书First Look, Silverlight 2

Tags:  silverlight2 silverlight.2.0 silverlight是什么 silverlight

延伸阅读

最新评论

发表评论