System.Windows.Markup.XamlParseException occurred
I have a datagrid bound to a list of objects. Users can add a new row below where the cursor is ( In code I create a new object and insert it in the list at the appropiate position).
Imagine that the datagrid has 4 rows
If the cursor is positioned in row number 4, then the row gets added, however, if the cursor is position in any of the other rows (1,2 or 3) then I get this exception:
System.Windows.Markup.XamlParseException occurred Message="Root element is missing." Source="PresentationFramework" LineNumber=0 LinePosition=0 StackTrace: at System.Windows.Markup.XamlReaderHelper.RethrowAsParseException(String keyString, Int32 lineNumber, Int32 linePosition, Exception innerException) InnerException: System.Xml.XmlException Message="Root element is missing." Source="System.Xml" LineNumber=0 LinePosition=0 SourceUri="" StackTrace: at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Windows.Markup.XmlCompatibilityReader.Read() at System.Windows.Markup.XamlReaderHelper.Read(XamlNode& xamlNode) InnerException:
NOTE: when the app first loads, if i first add a row (by being in the last row), then i am also able to add a row from any of the other rows. However, if i first try to add a row from row numbers 1,2,3 then it fails!
Any help will be greatly appreciated. I am totally lost. I doubt anyone else has e开发者_如何学Goxperienced this, but maybe you know what can be causing this or how I could debug it, as I do not know where to start :(
private void OnAddRowBelowCursor(DataGrid datagrid)
{
try
{
int index = datagrid.SelectedIndex;
MyObject newObj = new MyObject();
ObjectList.Insert(index + 1, newObj);
Logging.log.Info("Appended object row below the cursor...");
}
catch (Exception ex)
{
Logging.log.Error("Error appending row below cursor. Reason: " + ex.ToString());
}
}
private void OnAppendRowToBottom()
{
try
{
MyObject newObj = new MyObject();
ObjectList.Add(newObj);
Logging.log.Info("Appended object row to bottom...");
}
catch (Exception ex)
{
Logging.log.Error("Error appending row to the bottom of the table. Reason: " + ex.ToString());
}
}
I have also notice that adding a row to the bottom does not fail
Thanks
Looks like the data Your are loading is badly formatted. I may sugest You such a solution, which will allow you to parse any XML or HTML source even if it's fails the validation
I was using the RTB from the extended library with an XAMLFormatter.
When creating a new row, I wasn't converting my empty string to XAML fortmat. Why it only fails when I was adding it below the cursor and not at the end, I still do not know. But it is fixed
精彩评论