我正在嘗試創建一個帶有藍色背景的邊框並重復圈子。作爲一個例子:在Silverlight中創建帶有重複元素的XAML邊框的正確方法是什麼?
對於垂直部分,我使用的在網格的垂直的StackPanel。在ControlTemplate中聲明一個圓圈(重疊一個藍色的Rectangle)。爲了產生重複,我複製了一堆ContentControls,每個ContentControl都指向我的ControlTemplate。
例如:
<StackPanel
Grid.Row="0"
Grid.RowSpan="3"
Grid.Column="0"
Orientation="Vertical"
>
<ContentControl
attachedProperties:LightEllipseAttachedProperties.LightState="{Binding ElementName=PhoneApplicationPage, Path=GameController.Instance.Lights}"
Template="{StaticResource LightbulbTemplate}"
/>
**Repeat N times**
<ContentControl
attachedProperties:LightEllipseAttachedProperties.LightState="{Binding ElementName=PhoneApplicationPage, Path=GameController.Instance.Lights}"
Template="{StaticResource LightbulbTemplate}"
/>
</StackPanel>
<ControlTemplate
x:Key="LightbulbTemplate"
>
<Grid>
<VisualStateManager.VisualStateGroups>
</VisualStateManager.VisualStateGroups>
<Rectangle
Fill="#3300CC"
Height="15"
Width="15"
/>
<Ellipse
x:Name="LightEllipse"
Height="8"
Width="8"
>
<Ellipse.Fill>
<SolidColorBrush />
</Ellipse.Fill>
</Ellipse>
</Grid>
</ControlTemplate>
我的問題:是否有更好的方法來創建使用Silverlight重複元素的邊界?也許Border具有平鋪功能,因此它會重複ControlTemplate本身,而不是添加單獨的ContentControls?
爲什麼不使用'ListBox'? –
你可以創建一個看起來正確的圖像嗎?創建大量的控件會讓你的應用程序變得更慢,並增加不必要的開銷。而且,除非它的尺寸完美,否則這些點不一定會在各個角落排列良好。 – WiredPrairie