【发布时间】:2013-01-05 02:37:24
【问题描述】:
我正在使用绑定填充UniformGrid。源是Square[,],UniformGrid中填充了Button对象。
这是我所做的: Data Binding between a double array and a grid
我在尝试执行此操作时收到 System.InvalidOperationException:
private void OnClickButton(object sender, RoutedEventArgs e)
{
Button b = (Button)sender;
UniformGrid grid = ItemControlGrid.ItemsPanel.LoadContent() as UniformGrid;
int rows = grille.Rows;
int columns = grille.Columns;
UIElementCollection children = grid.Children; // I get the Exception here
int index = children.IndexOf(b);
int row = index / columns;
int column = index % rows;
}
这是我的 XAML:
<ItemsControl Background="Gray" Margin="0" Width="800" Height="800"
x:Name="ItemControlGrid"
ItemsSource="{Binding MapGrid}"
ItemTemplateSelector="{StaticResource selector}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid
IsItemsHost="true"
x:Name="My_UniformGrid" Rows="25" Columns="25"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
为什么我会收到这个Exception?
【问题讨论】:
-
我们需要更多,让孩子们不应该抛出异常。异常消息中有什么内容吗?