Note that there are some explanatory texts on larger screens.

plurals
  1. PORead only one Record from the XML file and display it on listbox in WPF
    primarykey
    data
    text
    <p>I have an Xml file and it has some Elements, I want to display only one on the Listbox and the listbox should be updated when new Records are added. The updating should be dynamic. I tried binding but it did not help.</p> <p>Here is my Xml file</p> <pre><code>&lt;empList&gt; &lt;Information&gt; &lt;Name&gt;Jack&lt;/Name&gt; &lt;Destination&gt;AA&lt;/Destination&gt; &lt;EmployeeID&gt;AA&lt;/EmployeeID&gt; &lt;/Information&gt; &lt;Information&gt; &lt;Name&gt;David&lt;/Name&gt; &lt;Destination&gt;BB&lt;/Destination&gt; &lt;EmployeeID&gt;BB&lt;/EmployeeID&gt; &lt;/Information&gt; &lt;Information&gt; &lt;Name&gt;Adam&lt;/Name&gt; &lt;Destination&gt;wdwad&lt;/Destination&gt; &lt;EmployeeID&gt;dwad&lt;/EmployeeID&gt; &lt;/Information&gt;&lt;/empList&gt; </code></pre> <p>This is the class file </p> <pre><code>public class Information { public string Name{ get; set; } public string Destination{ get; set; } public string EmployeeID{ get; set; } } </code></pre> <p>This is the Collection class file</p> <pre><code>public class Collection { public List&lt;Information&gt; empList = new List&lt;Information&gt;(); } </code></pre> <p>This is the .cs file</p> <pre><code>private void Window_Loaded(object sender, RoutedEventArgs e) { XmlSerializer xs = new XmlSerializer(typeof(Collection)); FileStream read = new FileStream("data.xml", FileMode.Open, FileAccess.Read, FileShare.Read); Collection coll = (Collection)xs.Deserialize(read); listBox1.ItemsSource = coll.empList; } </code></pre> <p>This is the XAML file</p> <pre><code> &lt;ListBox Height="251" HorizontalAlignment="Left" Margin="334,22,0,0" Name="listBox1" VerticalAlignment="Top" Width="170" DataContext="{Binding {StaticResource Data}, XPath=empList/Information}" ItemsSource="{Binding XPath=Information/@Name}" /&gt; </code></pre> <p>Now i want to display only name on the listbox and the listbox should be automatically updated when new records are added. When i execute the abov mentioned code, i get an exception in the xaml file like "Provide value on 'System.Windows.StaticResourceExtension"</p>
    singulars
    1. This table or related slice is empty.
    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.
    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