【发布时间】:2014-02-15 19:37:46
【问题描述】:
我正在尝试创建一个带有蓝色背景和重复圆圈的边框。举个例子:
对于垂直部分,我在网格中使用垂直 StackPanel。在 ControlTemplate 中声明了一个圆(与蓝色矩形重叠)。为了产生重复,我复制粘贴了一堆 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 本身,而不是我添加单独的 ContentControl?
【问题讨论】:
-
为什么不使用
ListBox? -
你能创建一个看起来正确的图像并使用它吗?创建大量控件可能会使您的应用程序变慢并增加不必要的开销。而且,除非它的尺寸完美,否则这些点不一定会在所有角落都排列整齐。
标签: silverlight xaml windows-phone-7 windows-phone-8 windows-phone