inotifypropertychanged

If a model implements INotifyPropertyChanged, how should ViewModel register/deregister for PropertyChanged event?

一笑奈何 提交于 2019-12-05 04:59:04
I have a Model which implements INotifyPropertyChanged and it may get updated by a background business thread. Its related ViewModel also implements INotifyPropertyChanged . And their View obviously binds to ViewModel. This View may be shown on multiple places, and my goal is that all of them get updated when the model changes. I know that ViewModel should register for PropertyChanged event of Model. But I don't know when and where is the best place for this registering and deregistering. Specially about the deregistering, since I'm scared of having hundreds of VM event handlers on the Model

Implement INotifyProperty changed on Static Property in WPF and Silverlight

依然范特西╮ 提交于 2019-12-05 03:05:35
问题 The question is how to implement INotifyPropertyChanged on a static property because the event you implement is not static, and cannot be called by a static property. Also, you cannot bind to a static property in Silverlight. I've seen this question pop up an a few forums with a variety of solutions, none of which were very satisfying. Well, I think I've found an elegant solution, but it's so simple I feel like I must be missing something. The answer is, to write a non-static property that

WPF DataGrid not updating on PropertyChanged

大城市里の小女人 提交于 2019-12-05 01:27:32
i've a problem updating my datagrid when clicking the button by using NotifyPropertyChanged. It works if i set the DataGrid.ItemsSource in code behind, but it doesn't if i set it in xaml. here's some code of code behind & xaml: namespace MyWpfDataBindingLab { public partial class NpcWindow : Window { DataCollection dc = new DataCollection(); public NpcWindow() { InitializeComponent(); //command binding code //... } private void Window_Loaded(object sender, RoutedEventArgs e) { //if i set the ItemsSource here, updating of the UI works //dataGrid1.ItemsSource = dc; } private void

INotifyPropertyChanged: Notify another class

亡梦爱人 提交于 2019-12-05 01:26:57
问题 I have a class (let's call it MyContainerClass )that is a container for several other classes (let's call them ClassA to ClassF ). ClassA to ClassF inherit the same base class (let's call it MyBaseClass ). In MyBaseClass I have an int property with the name Count , which ClassA to ClassF inherit. I also have an int property with the same name in MyContainerClass which is the sum of ClassA to ClassF . Then I have a datagrid, and each row has one object of MyContainerClass . The columns of the

WPF: INotifyPropertyChanged And derived properties on different objects

那年仲夏 提交于 2019-12-04 22:43:17
Recently I inherited a pretty big project developed in C# and WPF. It uses bindings along with the INotifyPropertyChanged interface to propagate changes to/from the View. A little preface: In different classes I have properties that depend on other properties in the same class (think for example the property "TaxCode" that depends on properties like "Name" and "Lastname"). With the help of some code I found here on SO (can't find again the answer though) I created the abstract class "ObservableObject" and the attribute "DependsOn". The source is the following: using System; using System

How do I use INotifyPropertyChanged in WinRT?

二次信任 提交于 2019-12-04 22:17:52
I'm a total newbie, just learning the basics of DataContext and the MVVM model. I've now got a grid bound to a view model object which implements INotifyPropertyChanged , however it appears that UpdateSourceTrigger (which all the WPF tutorials tell me to use) is not available for WinRT / Metro Style apps! How do I implement INotifyPropertyChanged then? I'm at the end of my tether here. I've spend nearly the whole day on the most basic of app examples, simply trying to get a grid to update after I click something. The only way I've managed to do this so far is to create an entirely new instance

Handling PropertyChanging/PropertyChanged via Castle's DynamicProxy

六眼飞鱼酱① 提交于 2019-12-04 19:29:39
I currently have a setter method which looks like this: private string _a; public virtual string A { get { return _a; } set { if (_a!= value) { if (this.OnPropertyChanging("A", _a, value)) { var previousValue = _a; _a = value; this.OnPropertyChanged("A", previousValue, value); } } } } I have implemented this with help from Dr Wily's Apprentice (http://stackoverflow.com/a/8578507/981225), with a custom Changing handler that keeps track of the old and current value, as well as the ability to set the Changing event as 'Cancelled', such that the PropertyChange will not occur. This works perfectly.

Should a setter return immediately if assigned the same value?

二次信任 提交于 2019-12-04 18:12:38
问题 In classes that implement INotifyPropertyChanged I often see this pattern : public string FirstName { get { return _customer.FirstName; } set { if (value == _customer.FirstName) return; _customer.FirstName = value; base.OnPropertyChanged("FirstName"); } } Precisely the lines if (value == _customer.FirstName) return; are bothering me. I've often did this but I am not that sure it's needed nor good. After all if a caller assigns the very same value I don't want to reassign the field and,

Simple small INotifyPropertyChanged implementation

坚强是说给别人听的谎言 提交于 2019-12-04 10:52:15
Say I have the following class: public MainFormViewModel { public String StatusText {get; set;} } What is the easiest smallest way to get my changes to StatusText to reflect to any controls that bind to it? Obviously I need to use INotifyPropertyChanged, but is there a cool way to do it that does not clutter up my code? need lots of files? etc? Note: If this is a dupe then I am sorry. I searched and could not find any thing but using T4 code Generation which does not sound easy (to setup at least). Unfortunately C# doesn't offer an easy mechanism to do that automatically... It has been

Binding static property and implementing INotifyPropertyChanged

岁酱吖の 提交于 2019-12-04 09:56:22
I'm trying to bind a static property of some class to some control. I've tryied a few implementation but each has its problem: All examples use the next XAML: <Label Name="label1" Content="{Binding Path=text}"/> 1st approach - don't use INotifyPropertyChanged public class foo1 { public static string text { get; set; } } The problem is that when 'text' propery changes the control is not notified. Second approach - use INotifyPropertyChanged public class foo1 : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyName) {