2011-02-18 44 views
1

我有3件事情我想在某些東西里包裝起來,這樣我就可以從代碼中調用容器,而不是分別調用每個東西。Silverlight - 一堆元素的基本容器

我可以看到有一個Canvas容器,但沒有更通用的東西,只是作爲一個包,我可以打電話?

這裏是我當前的代碼:

<Rectangle Grid.Column="0" Grid.Row="3" Grid.RowSpan="2" Grid.ColumnSpan="3" Fill="Black" Width="420" Height="480" Opacity=".5"></Rectangle> 
<Rectangle Grid.Column="0" Grid.Row="3" Grid.RowSpan="2" Grid.ColumnSpan="3" Fill="Black" Width="100" Height="50" VerticalAlignment="Top" Margin="0,50,0,0" RadiusX="5" RadiusY="5"></Rectangle> 
<TextBlock Grid.Column="0" Grid.Row="3" Grid.RowSpan="2" Grid.ColumnSpan="3" Foreground="White" Text="Loading" HorizontalAlignment="Center" Margin="0,65,0,0"></TextBlock> 

我希望我能做到這一點:

<Container> 
    <Rectangle Grid.Column="0" Grid.Row="3" Grid.RowSpan="2" Grid.ColumnSpan="3" Fill="Black" Width="420" Height="480" Opacity=".5"></Rectangle> 
    <Rectangle Grid.Column="0" Grid.Row="3" Grid.RowSpan="2" Grid.ColumnSpan="3" Fill="Black" Width="100" Height="50" VerticalAlignment="Top" Margin="0,50,0,0" RadiusX="5" RadiusY="5"></Rectangle> 
    <TextBlock Grid.Column="0" Grid.Row="3" Grid.RowSpan="2" Grid.ColumnSpan="3" Foreground="White" Text="Loading" HorizontalAlignment="Center" Margin="0,65,0,0"></TextBlock> 
</Container> 

BTW,這應該是這個樣子:

--------------- 
| --------- | 
| | Loading | | 
| --------- | 
|    | 
|    | 
|    | 
|    | 
--------------- 

謝謝,

Aaron

回答

1

這個問題沒有多大意義,但你在尋找一個UserControl

(鏈接指向的Silverlight 2.0,但它仍然是有效的),如果你想在風格與控制一個模板,你需要一個Custom Control(從Control繼承)