Note that there are some explanatory texts on larger screens.

plurals
  1. POEditing XML in Windows Store using MVVM and Message
    primarykey
    data
    text
    <p>In my application I am creating XML in <a href="https://github.com/tkowalczyk/NumbersGame/blob/master/NumbersGame/NumbersGame.Win8/App.xaml.cs" rel="nofollow">App.xaml.cs</a> like this:</p> <pre><code>public async static void CreateBadgesXML() { StorageFolder sf = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Data", CreationCollisionOption.OpenIfExists); StorageFile st = await sf.CreateFileAsync("Badgess.xml", CreationCollisionOption.ReplaceExisting); XmlDocument dom = new XmlDocument(); XmlElement x; x = dom.CreateElement("badges"); dom.AppendChild(x); XmlElement x1 = dom.CreateElement("badge"); XmlElement x11 = dom.CreateElement("id"); x11.InnerText = "1"; x1.AppendChild(x11); XmlElement x12 = dom.CreateElement("name"); x12.InnerText = "Badge One"; x1.AppendChild(x12); XmlElement x13 = dom.CreateElement("pictureurl"); x13.InnerText = "two.png"; x1.AppendChild(x13); XmlElement x14 = dom.CreateElement("isachieved"); x14.InnerText = "false"; x1.AppendChild(x14); x.AppendChild(x1); await dom.SaveToFileAsync(st); } </code></pre> <p>Next in <a href="https://github.com/tkowalczyk/NumbersGame/blob/master/NumbersGame/NumbersGame.Shared/ViewModel/MainViewModel.cs" rel="nofollow">MainViewModel</a> I am binding these data using reposiory pattern to ObservableCollection like this:</p> <pre><code>IList&lt;Badge&gt; list = await _badgeService.GetAll(); BadgesList = list.ToObservableCollection&lt;Badge&gt;(); </code></pre> <p>But when I am going to edit this XML in another View which is connected to another VievModel (<a href="https://github.com/tkowalczyk/NumbersGame/blob/master/NumbersGame/NumbersGame.Shared/ViewModel/QuestionViewModel.cs" rel="nofollow">QuestionViewModel</a>) like this:</p> <pre><code>public async Task Update(int id) { StorageFolder sf = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Data", CreationCollisionOption.ReplaceExisting); StorageFile st = await sf.CreateFileAsync("Badgess.xml", CreationCollisionOption.ReplaceExisting); XmlDocument dom = new XmlDocument(); XmlElement x; x = dom.CreateElement("badges"); dom.AppendChild(x); XmlElement x1 = dom.CreateElement("badge"); XmlElement x11 = dom.CreateElement("id"); x11.InnerText = "1"; x1.AppendChild(x11); XmlElement x12 = dom.CreateElement("name"); x12.InnerText = "Badge One"; x1.AppendChild(x12); XmlElement x13 = dom.CreateElement("pictureurl"); x13.InnerText = "two.png"; x1.AppendChild(x13); XmlElement x14 = dom.CreateElement("isachieved"); x14.InnerText = "true"; x1.AppendChild(x14); x.AppendChild(x1); await dom.SaveToFileAsync(st); } </code></pre> <p>And sending a Message from QuestionViewModel to MainViewModel like this:</p> <pre><code>Messenger.Default.Send&lt;CleanUp&gt;(new CleanUp()); </code></pre> <p>And try to bind this collection again:</p> <pre><code>private void CallCleanUp(CleanUp obj) { BadgesList = null; GetBadges(); } </code></pre> <p>I get an error XmlException "Root element is missing." I do not understand why after XML update, content of this file is empty? Any ideas?</p> <p><strong>EDIT</strong> After changes in update method, now I've got an UnauthorizedAccessException in <code>GetAll()</code> method in my <a href="https://github.com/tkowalczyk/NumbersGame/blob/master/NumbersGame/NumbersGame.Win8/Services/XML/BadgeService.cs" rel="nofollow">BadgeService</a>, still strange because in appears only after update XML.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload