I imagine you're showing the Datagrid in the Panel for the UnitTest. Keep in mind that it uses a VirtualizingStackPanel, so if there's no visible area, I would expect that no rows will be created (althoug I would at least expect to have a DataGridRowsPresenter) so I'm not sure if that could be the issue. The other problem might be timing. Try queuing the with a delay of 200ms after setting the ItemsSource.
On Tue, Mar 9, 2010 at 5:31 PM, Stephen Price <step...@perthprojects.com>wrote: > Strange, Not getting a DataGridRowsPresenter or any children from the > datagrid in the unit test. I think I need to look at what data is in it, and > somehow mock it (so it's still a unit test and not an integration test). The > viewmodel data object its binding to is pretty complicated. I just want > enough data there for it to give me a row or two. > > Those examples are great, should help me out once I get something actually > in the datagrid! Took a while for the penny to drop. > > cheers, > Stephen > > On Tue, Mar 9, 2010 at 12:22 PM, Miguel Madero <m...@miguelmadero.com>wrote: > >> With the class that I send you you can use the Extension method >> GetChildren (for UIElements), use the recursive overload to find a >> ToggleButton, it should look something like >> >> datagrid.GetChildren<ToggleButton>(true); >> >> This will return an IEnumerable of all the ToggleButtons in the DataGrid. >> This might include the ones used for sorting in the Header. TO exclude them, >> hou could get to the DataGridRowsPresenter (you should only have one) and >> then find all the Toggles there. >> >> >> dataGrid.GetChild<DataGridRowsPresenter>(true).GetChildren<ToggleButton>(); >> >> I'm not sure if I wrote a generic GetChild, but you could use >> >> >> dataGrid.GetChildren<DataGridRowsPresenter>(true).First().GetChildren<ToggleButton>(); >> >> >> If you don't use this helpers (or somethign similar), finding things in >> the tree is a mess and error prone with controls like the Datagrid that >> heavily use templates. >> >> >> -- >> Miguel A. Madero Reyes >> www.miguelmadero.com (blog) >> m...@miguelmadero.com >> >> _______________________________________________ >> ozsilverlight mailing list >> ozsilverlight@ozsilverlight.com >> http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight >> >> > > _______________________________________________ > ozsilverlight mailing list > ozsilverlight@ozsilverlight.com > http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight -- Miguel A. Madero Reyes www.miguelmadero.com (blog) m...@miguelmadero.com
_______________________________________________ ozsilverlight mailing list ozsilverlight@ozsilverlight.com http://prdlxvm0001.codify.net/mailman/listinfo/ozsilverlight