网站建设合集,网站seo优化免费,WordPress电影网站源码,安徽建设厅证书查询网网站概要#xff1a; 这个类似于封装控件样式。不过封装的是整个或是多个控件罢了#xff0c;然后用的时候就可以直接引用过来了。 创建用户控#xff1a; 这个也很简单#xff0c;不过有几个地方需要注意下。这个就不照抄了#xff0c;咱们也自己写一个。 步骤#xff1a…概要 这个类似于封装控件样式。不过封装的是整个或是多个控件罢了然后用的时候就可以直接引用过来了。 创建用户控 这个也很简单不过有几个地方需要注意下。这个就不照抄了咱们也自己写一个。 步骤 1.在SilverlightApplication中添加SilverlightUserControl。 2.发现新建的是 打开看一下这个文件跟MainPage一样一样的。但是你不能把它当做MainPage用如果你想用的话你要到App.xaml 中修改启动 private void Application_Startup(object sender, StartupEventArgs e) {this.RootVisual new MainPage(); } 3.在SilverlightControl1.xaml中添加代码代码Grid x:NameLayoutRoot Background#46461FGrid.RowDefinitionsRowDefinition/RowDefinitionRowDefinition/RowDefinitionRowDefinition/RowDefinition/Grid.RowDefinitionsGrid.ColumnDefinitionsColumnDefinition/ColumnDefinitionColumnDefinition/ColumnDefinition/Grid.ColumnDefinitionsTextBlock Grid.Row0 Grid.Column0 Text账户 Width50 Height20/TextBlockTextBox Grid.Row0 Grid.Column1 Width200 Height20/TextBoxTextBlock Grid.Row1 Grid.Column0 Text密码 Width50 Height20/TextBlockTextBox Grid.Row1 Grid.Column1 Width200 Height20/TextBoxButton Grid.Row2 Grid.Column0 Grid.ColumnSpan2 Content提交 BackgroundOrange Width200 Height100/Button/Grid 4.在MainPage.xaml添加代码代码UserControl x:ClassSilverlightAppDemo10.MainPage xmlns:myControlclr-namespace:SilverlightAppDemo10 xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml xmlns:dhttp://schemas.microsoft.com/expression/blend/2008 xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006 mc:Ignorabled d:DesignHeight300 d:DesignWidth400Grid x:NameLayoutRoot BackgroundWhitemyControl:SilverlightControl1 x:Namemycon/myControl:SilverlightControl1/Grid/UserControl 主要就是 注册xmlns:myControlclr-namespace:SilverlightAppDemo10 使用或引用myControl:SilverlightControl1 x:Namemycon/myControl:SilverlightControl1 这些代码vs会出现输入提示的。。。 5.看看效果。我晕还真难看。。。 添加用户控件属性 哎本想show一下asp.net控件开发知识的。结果没成功把代码贴上了。我会继续研究原因的也请知道的朋友告诉我一下。SilverlightControl.xaml代码 代码Canvas x:NameLayoutRoot BackgroundWhiteTextBlock x:Nametxtb Canvas.Left20 Canvas.Top50 Width100 Height20 Text/TextBlockTextBox Canvas.Left150 Canvas.Top50 Width200 Height20/TextBox/Canvas SilverlightControl.xaml.cs代码 代码public string TextMessage {get {return this.txtb.Text!?this.txtb.Text:还没有定义属性; }set {this.txtb.Text value; } } MainPage.xaml代码Grid x:NameLayoutRoot BackgroundWhitemyControl:SilverlightControl1 x:NamemyCon TextMessage没成功啊/myControl:SilverlightControl1/Grid 运行一下我想的是假如没有设置Text就会显示还没有定义属性 ,设置后就会显示设置的属性。可是这个Silverlight机制我不太懂弄巧成拙了。 动态添加用户控件 时间不够了先把TerryLee的贴上。回头我再改。另外我在想既然可以动态添加是不是也可以动态减去这样的话页面岂不是花样百出了我会明天继续。。1.用户控件可以动态的添加到页面中修改一下Page.xaml中的XAML代码放入一个Canvas作为用户控件的容器。 Grid x:NameLayoutRoot Background#46461F Canvas x:NameContainerCanvas /Canvas/Grid 编写添加用户控件代码 private void LayoutRoot_Loaded(object sender, RoutedEventArgs e){ ConfirmBox confirmbox new ConfirmBox(); confirmbox.Message 动态添加用户控件成功; ContainerCanvas.Children.Add(confirmbox);} 后记 现在有两个问题 1.动态修改用户控件属性即上面那个代码中get{}set{}为什么不能成功怎样才能成功 2.能否动态卸载控件这篇是我昨晚写的不过关机的时候忘记保存了。。今天重做一下传了上来。今天是我生日我出去玩了。晚上回来我会继续研究者两个问题。总目录上一篇vs2010 学习Silverlight学习笔记(7)控件样式与模板下一篇vs2010 学习Silverlight学习笔记(9)使用用户控件2转载于:https://www.cnblogs.com/yaoge/archive/2010/05/10/1731739.html