Silverlight用戶控件屬性添加方法介紹
作者:佚名
Silverlight用戶控件屬性的添加方法對于剛剛接觸這一開發(fā)工具的朋友來說可能還不太容易掌握。我們可以通過不斷的實(shí)踐來積累這方面的經(jīng)驗(yàn)。
Silverlight工具的推出,對于開發(fā)人員來說是一個(gè)劃時(shí)代的產(chǎn)物。它的靈活應(yīng)用,方便的實(shí)現(xiàn)了開發(fā)人員操作音頻視頻的簡單步驟。并且這款開發(fā)工具能夠支持各種平臺(tái),方便使用。#t#
Silverlight用戶控件屬性的添加代碼示例如下:
- < Grid x:Name="LayoutRoot" Background="White">
- < Rectangle HorizontalAlignment=
"Stretch" VerticalAlignment="Stretch" - Opacity="0.7" Fill="#FF8A8A8A"/>
- < Border CornerRadius="15" Width="400"
Height="150" Background="LightPink"
Opacity="0.9"> - < Grid>
- < Grid.RowDefinitions>
- < RowDefinition Height="60">< /RowDefinition>
- < RowDefinition Height="90">< /RowDefinition>
- < /Grid.RowDefinitions>
- < Grid.ColumnDefinitions>
- < ColumnDefinition>< /ColumnDefinition>
- < /Grid.ColumnDefinitions>
- < TextBlock x:Name="message"
FontSize="18" Foreground="White" - HorizontalAlignment="Left"
VerticalAlignment="Center" - Margin="50 20 0 0"/>
- < StackPanel Orientation="Horizontal"
Height="50" Grid.Row="1"> - < Image Source="info.png"
Margin="10 0 0 0">< /Image> - < Button Background="Red"
Width="120" Height="40" - Content="OK" Margin="10 0 0 0"
FontSize="18"/> - < Button Background="Red"
Width="120" Height="40" - Content="Cancel" Margin="50 0 0 0"
FontSize="18"/> - < /StackPanel>
- < /Grid>
- < /Border>
- < /Grid>
定義Silverlight用戶控件屬性:
- public partial class
ConfirmBox : UserControl- {
- public ConfirmBox()
- {
- InitializeComponent();
- }
- public String Message
- {
- get { return this.message.Text; }
- set { this.message.Text = value; }
- }
- }
在頁面使用Silverlight用戶控件屬性,XAML編輯器能夠識(shí)別出屬性并給出提示。
為ConfirmBox控件的Message屬性賦值:
- < Grid x:Name="LayoutRoot"
Background="#46461F">- < uc:ConfirmBox x:Name="mybox"
Message="使用用戶控件成功">- < /uc:ConfirmBox>
- < /Grid>
責(zé)任編輯:曹凱
來源:
博客園