wpf - How can I bind a List as ItemSource to ListView in XAML? -


I am learning WPF and want to make a collection similar to a linked list where I can add or remove strings. And I have to put a ListView , which listens to that collection with databasing. How can I share a simple list in XAML in ListView ?

My idea (not working) is something like this:

  & lt; Window x: Class = "TestApp.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/ 2006 / Xaml "title =" main window "height =" 350 "width =" 525 "& gt; & Lt; Window.Resources & gt; & Lt; Linkedist X: key = "myList" & gt; & Lt; / Linkedist & gt; // false & lt; window. Resources & gt; & Lt; Grid & gt; & Lt; ListView height = "100" horizontal alignment = "left" margin = "88,134,0,0" name = "listview 1" vertical alignment = "top" width = "120" itemsource = "{binding source = {static resource miliist}} "/> // false & lt; / Grid & gt; & Lt; / Window & gt;  

All of my code (updated version, not working):

  & lt; Window x: Class = "TestApp.MainWindow" Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/ 2006 / xaml "title =" main window "height =" 350 "width =" 525 "& gt; & Lt; Grid & gt; & Lt; Text box height = "23" horizontal align = "left" margin = "12,12,0,0" name = "text box" vertical alignment = "top" width = "120" /> & Lt; Button content = "button" height = "23" horizontal tracing = "true" margin = "0,12,290,0" name = "button1" workspaceElement = "top" width = "75" click = "button1_click" / Gt; & Lt; ListView height = "100" horizontal alignment = "left" margin = "88,134,0,0" name = "list view 1" vertical alignment = "top" width = "120" itemsource = "{Binding Marylist}" /> & Lt; / Grid & gt; & Lt; / Window & gt;  

C # -Code:

  Namespace TestAp {Public partial square main window: window {Inspectable collection & lt; String & gt; MyList = New Observational Collection & lt; String & gt; (); Public Manvindo () {Initialization (); MyList.Add ("First String"); } Private Zero Button 1_Click (Object Sender, RoutedEventArgs e) {myList.Add (textbox1.Text); Textbox1.Text = myList.Count + "st"; }}}}  

You can only dataset for public properties, Contents must be set.

  public partial class main window: window {public supervision qualification & lt; String & gt; MyList {Receives; Private set; } Public Main Window () {InitializeComponent (); MyList = New Observational Collection & lt; String & gt; (); MyList.Add ("First String"); DataContext = This; } Private Zero Button 1_Click (Object Sender, RoutedEventArgs e) {myList.Add (textbox1.Text); Textbox1.Text = myList.Count + "st"; }}  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -