I have a grid withcolumns=3 and rows = 5. Each cell contains the same custom user control created at runtime. Each custom user control have a name and others properties differents.
我有一个gridcolumns = 3和rows = 5的网格。每个单元格包含在运行时创建的相同的自定义用户控件。每个自定义用户控件都有一个名称,其他属性不同。
So far so good....
到现在为止还挺好....
When I try to get the object inside an specific cell I used (vb.net and WPF) this code:
当我尝试将对象放入我使用的特定单元格(vb.net和WPF)时,此代码:
Dim currentContainer As ObjectContainerControl = ContainerGrid.Children.Cast(Of UIElement)().OfType(Of ObjectContainerControl)().Where(Function(c) Grid.GetRow(c) = 0 And Grid.GetColumn(c) = 0)
Where ObjectContainerControl
is my custom user control and container Grid is my grid'sname
ObjectContainerControl是我的自定义用户控件,容器Grid是我的grid'sname
This line send me the following error:
这行发给我以下错误:
Unable to cast object of type WhereEnumerableIterator'1[MyProject.ObjectContainerControl]
to type My.ObjectContainerControl
.
无法将WhereEnumerableIterator'1 [MyProject.ObjectContainerControl]类型的对象强制转换为My.ObjectContainerControl类型。
How can i fix this???
我怎样才能解决这个问题???
1 个解决方案
#1
0
You need to select an element from the IEnumerable you get in your current query.
您需要从当前查询中获得的IEnumerable中选择一个元素。
Call the First method as the last step in your query, to get the right element.
调用First方法作为查询的最后一步,以获取正确的元素。
Dim currentContainer As ObjectContainerControl =
ContainerGrid.Children.Cast(Of UIElement)().OfType(Of ObjectContainerControl)()
.Where(Function(c) Grid.GetRow(c) = 0 And Grid.GetColumn(c) = 0).**First()**
#1
0
You need to select an element from the IEnumerable you get in your current query.
您需要从当前查询中获得的IEnumerable中选择一个元素。
Call the First method as the last step in your query, to get the right element.
调用First方法作为查询的最后一步,以获取正确的元素。
Dim currentContainer As ObjectContainerControl =
ContainerGrid.Children.Cast(Of UIElement)().OfType(Of ObjectContainerControl)()
.Where(Function(c) Grid.GetRow(c) = 0 And Grid.GetColumn(c) = 0).**First()**