wpf - How to force ListBox to reload properties of ListBoxItems -
Is there any way, how to implement an observable collection to collect?
I have an object of observation ListBox item source, so every time I add / delete items in the collection, the list varies accordingly, but when I have some objects in the archive I change the properties of the box, the list box still presents the old value.
Even if I modify some properties and then add / remove objects in the collection, nothing happens, yet I look at the old values.
Is there any other way to do this? I got the INOTifyPropertyChanged interface, but how do I use it?
Agree to Matt's comments above. Here's a small code to show how to implement INOTifyPropertyChanged.
=========== ============
Using the system behind code codes ; Using System.Collections.Generic; Using System.Linq; Using System.Text; Using System.Windows; Using System.Windows.Data; Using System.Windows.Documents; Namespace WpfApplication1 {/// & lt; Summary & gt; /// Window 1. Interaction logic for xaml /// & lt; / Summary & gt; Public partial squares window 1: windows {names of names; Public Window 1 () {InitializeComponent (); This.addButton.Click + = addButton_Click; This.names = new alias (); DockPanel.DataContext = this.names; } Zero addButton_Click (Object Sender, RoutedEventArgs e) {this.names.Add (new alias (myName.Text, myNick.Text)); }} Public category nickname: System. compilation. Object Modelel. Observeable collection & lt; Nickname & gt; {} Public Category Alias: System.ComponentModel.INotifyPropertyChanged {Public Event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; Zero notification (string Pronam) {if (property changed! = Null) {property has changed (this, new Sistmkkanpanentmodelkproprti Chenglted Iventarj (Propanam)); }} String name; Public string name {get {return name; } Set {name = value; Inform ("name"); }} String nick; Public string nick {get {return nick; } Set {nick = value; Inform ("Nick"); }} Public alias (): This ("name", "nick") {} public alias (string name, string nick) {this.name = name; This.nick = Nick; } Public override string toasting () {name back Toasting () + "" + nick Toasting (); }}} XAML
& lt; Window x: orbit = "wpfApplication1.Window1" xmlns = "http://schemas.microsoft.com / winfx / 2006 / xaml / presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/ Xaml "title =" window 1 "height =" 300 "width =" 300 "& gt; & Lt; Grid & gt; & Lt; DocPanel X: Name = "DockPanel" & gt; & Lt; TextBox DockPanel.Doc = "Top" & gt; & Lt; Text Block Vertical Element = "Center" & gt; Name: & lt; / TextBlock & gt; & Lt; Text box text = "{binding path = name}" name = "my name" /> & Lt; Text Block Vertical Element = "Center" & gt; Nick: & lt; / TextBlock & gt; & Lt; Text box text = "{binding path = nick}" name = "myNick" /> & Lt; / TextBlock & gt; & Lt; Button dockpanel.doc = "bottom" x: name = "adbutton" & gt; Add & lt; / Button & gt; & Lt; ListBox ItemsSource = "{binding}" isSynchronizedWithCurrentItem = "True" /> & Lt; / DockPanel & gt; & Lt; / Grid & gt;
Comments
Post a Comment