WEB开发网
开发学院图形图像Flash 在Silverlight2 Beta2中开发自定义控件 阅读

在Silverlight2 Beta2中开发自定义控件

 2008-11-07 11:47:28 来源:WEB开发网   
核心提示: 二:创建控件模板下面我们为控件提供一个默认的控件模板,像类库项目中添加添加Generic.xaml文件,在Silverlight2 Beta2中开发自定义控件(2),代码如下: <ResourceDictionaryxmlns="http://schemas.microso

在Silverlight2 Beta2中开发自定义控件 

二:创建控件模板

下面我们为控件提供一个默认的控件模板,像类库项目中添加添加Generic.xaml文件,代码如下:

<ResourceDictionary
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 xmlns:custom="clr-namespace:CarySLCustomControlLib;assembly=CarySLCustomControlLib"
    <Style TargetType="custom:CarySLCustomControl">
    <Setter Property="Template">
     <Setter.Value>
      <ControlTemplate TargetType="custom:CarySLCustomControl">
       <Grid x:Name="RootElement">
        <Rectangle x:Name="BodyElement" Width="200" Height="100"
              Fill="LightCoral" Stroke="Purple" RadiusX="16" RadiusY="16" />
        <TextBlock Text="Cary Click" HorizontalAlignment="Center"VerticalAlignment="Center" />
       </Grid>
      </ControlTemplate>
     </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>
  
向我们的控件类CarySLCustomControl的构造函数中添加如下代码:this.DefaultStyleKey = typeof(CarySLCustomControl);在Page.xaml中我们只需要引用控件<custom:CarySLCustomControl/>,就可以达到上面一样的效果了。

上一页  1 2 3 4 5 6  下一页

Tags:Silverlight 开发

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接