I am learning wpf. I am trying to utilize tdd practices with wpf. I have the following code in one of my viewmodels that saves data from a control into an xml file -
void saveStr()
{
string source = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Data\Connections.xml";
DataGrid dg = FindChildViewItems.FindChild<DataGrid>(Application.Current.MainWindow, "MyDataGrid");
List<XmlSettings> list = new List<XmlSettings>();
foreach (var i in dg.Items)
{
if(i.GetType().ToString() == "MyProject.Configuration.XmlSettings")
{
list.Add((XmlSettings)i);
}
}
saveXml.Save(source, list);
}
The FindChildViewItems simply uses the visualtreehelper and dependency objects to find child items from the view (adapted from a post here).
My question is whether that adheres to tdd patterns since it has a dependency on the view when I am looking back to the view to get the contents of that particular control.
Is there another way to get the information from the datagrid on the view so that the contained data could be saved to an xml file. I hope that makes sense......
Thanks for any thoughts.