概要:

  这个类似于封装控件样式。不过封装的是整个或是多个控件罢了,然后用的时候就可以直接引用过来了。

创建用户控:

  这个也很简单,不过有几个地方需要注意下。这个就不照抄了,咱们也自己写一个。
  步骤:
  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:Name="LayoutRoot" Background="#46461F">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="账户"
Width
="50" Height="20"></TextBlock>
<TextBox Grid.Row="0" Grid.Column="1" Width="200" Height="20"></TextBox>
<TextBlock Grid.Row="1" Grid.Column="0" Text="密码"
Width
="50" Height="20"></TextBlock>
<TextBox Grid.Row="1" Grid.Column="1" Width="200" Height="20"></TextBox>
<Button Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Content="提交"
Background
="Orange" Width="200" Height="100"></Button>
</Grid>

相关文章: