❔ System.InvalidCast Exception when looping through Controls.Grid.Children
System.InvalidCastException: 'Unable to cast object of type 'System.Windows.Controls.Button' to type 'System.Windows.Controls.UIElementCollection'.'
trying to programatically add buttons to a grid, but I'm getting this error when looping through the grids children.
this is where I'm looping through it
this is the XAML defining the rows & columns
2 Replies
heres a gist with where I'm calling the function as well
https://gist.github.com/Dawwa1/7dc1880282572486b0bbf79aa0b26219
Gist
System.InvalidCast Exception when looping through Controls.Grid.Chi...
System.InvalidCast Exception when looping through Controls.Grid.Children - MainWindow.xaml.cs
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.