怎么创建silverlight custom control
2009-02-26 11:56
141 查看
这篇文章主要是介绍一下简单的Custom Control 的创建方法。
工具是vs2008
1. 首先建立一个siverlight应用程序,我这里暂时命名为CustomControl
2. 然后再建立一个Siverlight Class Library, 在这个Library工程里面建一个名字为themes的文件夹,在这个文件夹里面建立一个名字为generic.xaml的文件。
3. 修改generic.xaml文件的属性, Build Action 的属性修改成Resource, 清空Custom Tool value的值。
4. 创建一个类继承自ItemsControl,名字自己选择,我选择的是LiScrollViewer 因为我想自己弄个简单的ScrollViewer
5. 在构造函数里面制定使用样式的方式:base.DefaultStyleKey = typeof(LiScrollViewer);
6. 修改generic.xaml的内容如下
7. 在这个CustomControl工程里面加入上个控件的引用,这样就可以在这个工程里面进行调用了。
修改工程 CustomControl里面的Page.xaml的内容如下:
8. 编译这个CustomControl工程即可,然后在网页里面调用这个silverlight控件(CustomControl.xap)就可以了
工具是vs2008
1. 首先建立一个siverlight应用程序,我这里暂时命名为CustomControl
2. 然后再建立一个Siverlight Class Library, 在这个Library工程里面建一个名字为themes的文件夹,在这个文件夹里面建立一个名字为generic.xaml的文件。
3. 修改generic.xaml文件的属性, Build Action 的属性修改成Resource, 清空Custom Tool value的值。
4. 创建一个类继承自ItemsControl,名字自己选择,我选择的是LiScrollViewer 因为我想自己弄个简单的ScrollViewer
5. 在构造函数里面制定使用样式的方式:base.DefaultStyleKey = typeof(LiScrollViewer);
6. 修改generic.xaml的内容如下
<Style x:Key="scrollviewStyle" TargetType="ScrollViewer"> <!--<Setter Property="IsEnabled" Value="true"></Setter> <Setter Property="BorderBrush" Value="#FFA4A4A4"/>--> </Style> <Style TargetType="lc:LiScrollViewer"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="lc:LiScrollViewer"> <Grid x:Name="Root"> <!--<Grid.ColumnDefinitions> <ColumnDefinition Width="100"></ColumnDefinition> <ColumnDefinition Width="100"></ColumnDefinition> </Grid.ColumnDefinitions>--> <Border> <ScrollViewer x:Name="ScrollViewer" Style="{StaticResource scrollviewStyle}" mce_Style="{StaticResource scrollviewStyle}" Background="AliceBlue"> <!--<ItemsPresenter></ItemsPresenter>--> </ScrollViewer> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
7. 在这个CustomControl工程里面加入上个控件的引用,这样就可以在这个工程里面进行调用了。
修改工程 CustomControl里面的Page.xaml的内容如下:
<UserControl x:Class="CustomControl.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300" xmlns:lc="clr-namespace:LiBaseControl;assembly=LiBaseControl"> <Grid x:Name="LayoutRoot" Background="White"> <lc:LiScrollViewer x:Name="ddd"></lc:LiScrollViewer> </Grid> </UserControl>
8. 编译这个CustomControl工程即可,然后在网页里面调用这个silverlight控件(CustomControl.xap)就可以了
相关文章推荐
- 综合应用WPF/WCF/WF/LINQ之三:采用用代码创建的方式实现CheckListBox的CustomControl
- Silverlight custom control属性的配置
- The run order about Loaded event and OnApplyTemplate in custom control of Silverlight 2 beta 2
- Creating a Custom Skin for Silverlight 's Button Control(收藏)
- 在创建的Silverlight Control中使用图片
- MicrosoftAjax中的Custom Control是怎么和Sys.UI.Control联系起来的?
- 创建Custom Control
- [转]Creating Custom Web Controls in C# Stats(演示了如何创建一个导航条)
- WPF Control Hints - ContextMenu : 怎么通过MenuItem的Click事件取得ContextMenuItem绑定的类实例?
- 线程间操作无效: 从不是创建控件“Control Name'”的线程访问它问题的解决方案及原理分析
- laravel怎么创建一个简单的blog
- win7中怎么创建宽带连接
- 创建自定义行为并在Silverlight项目中使用2
- UISegmentedControl custom color
- 怎么在外部类的静态方法中创建成员内部类的对象?
- 如何使用VC中的Custom Control?
- Silverlight+RIA Service创建企业商业应用(1)基础导航
- Silverlight ItemsControl详细解析+解惑
- [Silverlight学习笔记]创建Silverlight 3与WCF之间的 双工通信
- Developing ASP.NET Custom Control With C# Builder