Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't this data binding working?
    text
    copied!<p>So I'm brand new to WPF data binding, and it is.. complicated. At this point, I'm trying to just create a list of premade test items and have it displayed in a listbox with a data template when I press a button. After hours of puzzling through tutorials and MSDN this is the best I could come up with. </p> <p>The data item I want to make a list from:</p> <pre><code>class ListingItem { private string title; private string user; private string category; //Dummy constructor for test purposes public ListingItem() { title = "TestTitle"; user = "TestUser"; category = "TestCatagory"; } } </code></pre> <p>The quick and dirty list creator:</p> <pre><code>class ListMaker { public static List&lt;ListingItem&gt; getListing() { List&lt;ListingItem&gt; listing = new List&lt;ListingItem&gt;(); for(int i = 0; i &lt;100; i++) { listing.Add(new ListingItem()); } return listing; } } </code></pre> <p>The XAML of the list itself:</p> <pre><code>&lt;ListBox x:Name="Listing"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Vertical"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Foreground="Gray" Margin="25,0,0,0" Text="{Binding user}"/&gt; &lt;TextBlock Foreground="Gray" Margin="25,0,0,0" Text="{Binding category}"/&gt; &lt;/StackPanel&gt; &lt;TextBlock Foreground="Black" Width="270" TextWrapping="Wrap" Text="{Binding title}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; </code></pre> <p></p> <p>And finally, the button click event which is SUPPOSED to make the magic happen: </p> <pre><code>private void TabClickEvent(object sender, RoutedEventArgs e) { Listing.DataContext = RedditScanner.getListing(); } </code></pre> <p>Problem is, obviously, the magic is not happening. No errors or anything so easy, I just press that button and dont see any change to the list box. Any help with this? </p>
 

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