❔ WPF Binding to collection in static instance not updating list

I have a collection in a static member of a class that's being changed. It should be firing PropertyChanged for the property shown below. But the list never updates.
dgPredefined.SetBinding(System.Windows.Controls.ItemsControl.ItemsSourceProperty, new System
.Windows.Data.Binding("AllItemsSortedByName")
{
Source = Data.NetworkMgr.mgr,
NotifyOnTargetUpdated = true,
});
dgPredefined.SetBinding(System.Windows.Controls.ItemsControl.ItemsSourceProperty, new System
.Windows.Data.Binding("AllItemsSortedByName")
{
Source = Data.NetworkMgr.mgr,
NotifyOnTargetUpdated = true,
});
The original plan was to declare it in the XAML, but I haven't figured out the equivalent syntax. Can someone tell me what I'm doing wrong? I tried both NotifyOnTargetUpdated as shown above and NotifyOnSourceUpdated. My orignal impression was the latter is for when the control needs to be notified the source has changed. But after reading the documentation, it looks like it's the other way around. With Data.NetworkMgr.mgr, Data is a namespace, NetworkMgr is a class, and mgr is the static instance of Data.NetworkMgr.
4 Replies
ACiDCA7
ACiDCA714mo ago
lets get the general stuff cleared first -why are you doing the binding in codebehind? -is mgr a list? -if its a list does it implement Inotifycollectionschanged? -does the class itself implement inotifypropertychanged -are you invoking onpropertychanged -maybe typo in propertyname? -is the "static instance" even a property? @Will Pittenger also some more code would help.. if its on github on so a link would be beneficial there is too much to guess from just your snippet
Will Pittenger
Will PittengerOP14mo ago
The class does implement INotifyPropertyChanged. I mentioned PropertyChanged. As for the collection, after I left last night, I realized the collection is the Values property a System.Collections.Generic.SortedDictionary expansion. Would that cause problems. Not yet, but I can make it one. I am firing PropertyChanged. And I checked the property name several times. No code on GitHub. The declaration chain with some extra stuff removed:
public abstract class ObjBase : System.ComponentModel.INotifyPropertyChanged
{
public abstract event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged;
}
public abstract class MgrBase : ObjBase
{
}
public class UserNetworkMgr : MgrBase
{
}
public abstract class ObjBase : System.ComponentModel.INotifyPropertyChanged
{
public abstract event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged;
}
public abstract class MgrBase : ObjBase
{
}
public class UserNetworkMgr : MgrBase
{
}
Got to go. Be back later. @ACiDCA7 So is there a collection option that might not have issues? The code I have now, still what's above, throws an exception in the dictionary's ValueCollection enumerator because the contents changed.
Will Pittenger
Will PittengerOP14mo ago
I did just create a repository on GitHub for it. https://github.com/ChatZilla-Replacement-Project/Best-Chat
GitHub
GitHub - ChatZilla-Replacement-Project/Best-Chat: This is a mockup ...
This is a mockup done in C# and WPF. Some functionality is present. - GitHub - ChatZilla-Replacement-Project/Best-Chat: This is a mockup done in C# and WPF. Some functionality is present.
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server