inotifypropertychanged

MVVM Best Practices: communication between view models

走远了吗. 提交于 2021-02-18 17:56:43
问题 My simplified program structure looks like this: public class Manager { public Item MyItem { get; set; } public void Recalculate(){ ... } } public class Item { public string SomeProperty { get; set; } } public class ManagerViewModel { public Manager Model { get; set; } public ItemViewModel MyItem { get; set; } } public class ItemViewModel { public Item Model { get; set; } public string SomeProperty { get => Model.SomeProperty; set { Model.SomeProperty = value; RaisePropertyChanged(

MVVM Best Practices: communication between view models

情到浓时终转凉″ 提交于 2021-02-18 17:56:27
问题 My simplified program structure looks like this: public class Manager { public Item MyItem { get; set; } public void Recalculate(){ ... } } public class Item { public string SomeProperty { get; set; } } public class ManagerViewModel { public Manager Model { get; set; } public ItemViewModel MyItem { get; set; } } public class ItemViewModel { public Item Model { get; set; } public string SomeProperty { get => Model.SomeProperty; set { Model.SomeProperty = value; RaisePropertyChanged(

Task parallel library INotifyPropertyChanged NOT throwing an exception?

孤人 提交于 2021-02-08 15:49:14
问题 I have a wpf project where I am using INotifyPropertyChanged on a property which binds to the textbox. I am updating this value on a different thread using task (TaskParallelLibrary). It is updated properly and does NOT throw an exception. I was thinking it would throw an exception because it is running on a background thread and not UI thread. Ofcourse it is throwing an exception if I directly use the UI element. So, does INotifyPropertyChanged bind mechanism takes care of dispatching to the

How to call a public event from a static function in the same class?

守給你的承諾、 提交于 2021-02-07 17:31:28
问题 I have a class that contains an ObservableCollection of another class. I want to be notified if one of the class members is changed, because I need to do some calculating in the MediaCollection class. So I added an event to that class: public event PropertyChangedEventHandler PropertyChangedEvent; which is called in this collection class: public class MediaCollection : INotifyPropertyChanged { private List<MediaEntry> ModifiedItems = new List<MediaEntry>(); private ObservableCollection

Good way to refresh databinding on all properties of a ViewModel when Model changes

只谈情不闲聊 提交于 2021-02-05 13:03:45
问题 Short Version If I update the Model object that my ViewModel wraps, what's a good way to fire property-change notifications for all the model's properties that my ViewModel exposes? Detailed Version I'm developing a WPF client following the MVVM pattern, and am attempting to handle incoming updates, from a service, to data being displayed in my Views. When the client receives an update, the update appears in the form of a DTO which I use as a Model. If this model is an update to an existing

INotifyPropertyChanged and consistency - when to raise PropertyChanged?

偶尔善良 提交于 2021-01-28 06:02:07
问题 I have a class that implements INotifyPropertyChanged . It has two properties whose values are related to each other, like, for example, a person's first and last name. If one property is updated, the other one needs to be updated as well. To communicate this I've made the setters private and added a public method to change both properties at the same time. My question is if there's any rule or convention as to when to raise the PropertyChanged event? I'd like to delay raising the events for

Does CallerMemberNameAttribute use reflection

雨燕双飞 提交于 2021-01-02 05:26:16
问题 You can use the CallerMemberName attribute to avoid specifying the member name as a String argument to the called method when implementing INotifyPropertyChanged interface. The question is does it use reflection behind the scene? Are there any performance hit over hard coding Property name? 回答1: No; the compiler hard-codes the member-name directly during compilation. In terms of the IL, this is ldstr . For example if we compile: static void Implicit() { Log(); } static void Explicit() { Log(

Does CallerMemberNameAttribute use reflection

我只是一个虾纸丫 提交于 2021-01-02 05:26:09
问题 You can use the CallerMemberName attribute to avoid specifying the member name as a String argument to the called method when implementing INotifyPropertyChanged interface. The question is does it use reflection behind the scene? Are there any performance hit over hard coding Property name? 回答1: No; the compiler hard-codes the member-name directly during compilation. In terms of the IL, this is ldstr . For example if we compile: static void Implicit() { Log(); } static void Explicit() { Log(

A Single Label can display 2 Data fields alternately select by user

倾然丶 夕夏残阳落幕 提交于 2020-12-15 06:18:18
问题 I'm trying to use a single Label to display one of the two data fields alternately in Xamarin Forms. Only Label 1 Display the binding field and second Label which I am trying to use a variable "DisplayField" is not displaying either 'Contact_Address' or 'Contact_eMail' Model class public class Contacts { [PrimaryKey][Autoincrement] public int Contact_ID { get; set; } public string Contact_Name { get; set; } public string Contact_Address { get; set; } public string Contact_eMail { get; set; }