在为 Windows Phone 8 编写应用程序时,我遇到了一个问题。在 ViewModel 我有
public ObservableCollection<Ball> ListOfBalls { get; set;}
每个 Ball 都有其行号和列号。
在 View 中,我指定Grid.Row
了要放入网格(10 行 x 10 列)的位置,然后我想将 ListOfBalls 中的一个球放入每个网格单元格中。
所以,那就是View
:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="5*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="GamePlayGrid"
Grid.Row="1"
Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- I've tried to add ItemsControl here -->
</Grid>
</Grid>
我尝试定义网格(10 行 x 10 列),然后在此网格的范围内我尝试添加ItemsControl
with DataTemplate
,但我不确定它是否正确,因为在执行期间我遇到了一些未处理的异常......我该如何修复这个?