In my WPF app the following should be possible:
reading in XML Data and presenting them in the User Interface.
To this end I defined a dataGrid in the MainPage.xaml file:
<DataGrid Name="dataGrid" AutoGenerateColumns="True" />
In the code-behind-file I created a method to fill this datagrid with data from an xml-file:
private void mnuOpen_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
string path = System.IO.Path.GetFullPath(dlg.FileName);
var xml = XDocument.Load(path).Root;
dataGrid.DataContext = xml;
}
}
This compiles fine and also runs fine (whithout throwing an exception) - however, the xml-data is not displayed in the UI.
When using the debugger, there are several strange things:
the variable "path" in the watch window looks as follows the whole time:path error CS0103: The name 'path' does not exist in the current context
for some reason, the line
var xml = XDocument.Load(path).Root;
seems to be "jumped over". That is, the debugger goes directly from
string path = System.IO.Path.GetFullPath(dlg.FileName);
to
dataGrid.DataContext = xml;
I don't really understand what's going on here.
DataContext?XmlDataProviderin your code?XmlDataProviderwork.