Note that there are some explanatory texts on larger screens.

plurals
  1. POC# WPF - Listview Binding not working
    primarykey
    data
    text
    <p>I have been trying to create a window in WPF and bind a listview to a list of objects, but I can't get the objects in the list to display in the listview.</p> <p>Here is the XAML of the window:</p> <pre><code>&lt;Window x:Class="WpfApplication.window_ManageInstruments" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="window_ManageInstruments" Height="400" Width="600" WindowStartupLocation="CenterOwner"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="100" /&gt; &lt;RowDefinition /&gt; &lt;/Grid.RowDefinitions&gt; &lt;ListView Grid.Row="1" Margin="5" Name="listInstruments" ItemsSource="{Binding InstrumentList}"&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Width="120" Header="Symbol" DisplayMemberBinding="{Binding Field1}"/&gt; &lt;GridViewColumn Width="200" Header="Description" DisplayMemberBinding="{Binding Field2}"/&gt; &lt;GridViewColumn Width="120" Header="Last Stats" DisplayMemberBinding="{Binding Field3}"/&gt; &lt;GridViewColumn Width="100" Header="Margin" DisplayMemberBinding="{Binding Field4}"/&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; &lt;Label HorizontalAlignment="Left" Margin="10,10,0,0" Name="label1" Width="120" Height="25" VerticalAlignment="Top"&gt;Symbol&lt;/Label&gt; &lt;Label HorizontalAlignment="Left" Margin="10,40,0,0" Name="label2" Width="120" Height="25"&gt;Description&lt;/Label&gt; &lt;TextBox Height="25" Margin="150,10,0,0" Name="txtSymbol" VerticalAlignment="Top" HorizontalAlignment="Left" Width="120" /&gt; &lt;TextBox Margin="150,40,0,0" Name="txtDescription" HorizontalAlignment="Left" Width="120" Height="25" /&gt; &lt;Button Height="23" HorizontalAlignment="Right" Margin="0,12,133,0" Name="btn_AddInstrument" VerticalAlignment="Top" Width="75"&gt;Add&lt;/Button&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>and here is the code-behind:</p> <pre> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Xml; using WpfApplication.classes; using System.Collections.ObjectModel; namespace WpfApplication { /// /// Interaction logic for window_ManageInstruments.xaml /// public partial class window_ManageInstruments : Window { public ObservableCollection InstrumentList = new ObservableCollection(); public window_ManageInstruments() { this.DataContext = this; InstrumentList.Add(new TestClass { Field1 = "A", Field2 = "B", Field3 = "C", Field4 = "D" }); InstrumentList.Add(new TestClass { Field1 = "E", Field2 = "F", Field3 = "G", Field4 = "H" }); InitializeComponent(); } } public class TestClass { public string Field1 { get; set; } public string Field2 { get; set; } public string Field3 { get; set; } public string Field4 { get; set; } } } </pre> <p>I don't know if I am missing any crucial configuration here, so any help would be greatly appreciated.</p> <p>Thank you in advance.</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.
    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