inotifypropertychanged

Bound WPF TextBox is not updating value when the bound property enforces some business rules

北慕城南 提交于 2019-12-18 17:14:24
问题 I am using .NET 4.0. I have some very simple code that lets the user type in a number between 1 and 99,999 (inclusive). I have some logic in the Property setter that prevents the latest value from being applied if it does not adhere to the business rules (e.g., it is not a number or the number is too large). public class MainViewModel : INotifyPropertyChanged { #region Fields private string _text = string.Empty; #endregion // Fields #region Properties public string Text { get { return _text;

List<string> INotifyPropertyChanged event

瘦欲@ 提交于 2019-12-18 12:48:50
问题 I have a simple class with a string property and a List property and I have the INofityPropertyChanged event implemented, but when I do an .Add to the string List this event is not hit so my Converter to display in the ListView is not hit. I am guessing the property changed is not hit for an Add to the List....how can I implement this in a way to get that property changed event hit??? Do I need to use some other type of collection?! Thanks for any help! namespace SVNQuickOpen.Configuration {

What's the best way to call INotifyPropertyChanged's PropertyChanged event? [duplicate]

泪湿孤枕 提交于 2019-12-18 12:27:01
问题 This question already has answers here : Implementing INotifyPropertyChanged - does a better way exist? (34 answers) Closed 4 months ago . When you implement the INotifyPropertyChanged interface, you're responsible for calling the PropertyChanged event each and everytime a property is updated in the class. This typically leads to the following code : public class MyClass: INotifyPropertyChanged private bool myfield; public bool MyField { get { return myfield; } set { if (myfield == value)

Determining the caller inside a setter — or setting properties, silently

旧城冷巷雨未停 提交于 2019-12-18 12:26:39
问题 Given a standard view model implementation, when a property changes, is there any way to determine the originator of the change? In other words, in the following view model, I would like the "sender" argument of the "PropertyChanged" event to be the actual object that called the Prop1 setter: public class ViewModel : INotifyPropertyChanged { public double Prop1 { get { return _prop1; } set { if (_prop1 == value) return; _prop1 = value; // here, can I determine the sender? RaisePropertyChanged

How to add a delay to a WPF program without blocking the UI

六眼飞鱼酱① 提交于 2019-12-18 07:07:34
问题 I am building a device emulator. When it starts, it takes some time for it to initialized. This would be logically represented by being turned on and going immediately to an "Initialization" state, and after some time it goes to "Ready" state. I am using MVVM, so the ViewModel will for now represent all the device logic. Each of the possible states have a datatriggered style to be rendered by the View. If I just set the state when I build the viewmodel, the view renders with the correct

How do I subscribe to PropertyChanged event in my ViewModel?

回眸只為那壹抹淺笑 提交于 2019-12-17 19:32:38
问题 I have core functionality encapsulated in ViewModelBase Now I want to see when PropertyChanged event was raised by ViewModelBase and act on it. For example, when one property was changed on ViewModelBase - I want to change property on my ViewModel How do I achieve this? public class MaintainGroupViewModel : BaseViewModel<MEMGroup> { public abstract class BaseViewModel<T> : NotificationObject, INavigationAware where T : Entity { 回答1: I am concerned that you're effectively doing a 'manual

Raising PropertyChanged for a dependent property, when a prerequisite property is changed in another class?

江枫思渺然 提交于 2019-12-17 19:03:37
问题 I have this Bank class: public class Bank : INotifyPropertyChanged { public Bank(Account account1, Account account2) { Account1 = account1; Account2 = account2; } public Account Account1 { get; } public Account Account2 { get; } public int Total => Account1.Balance + Account2.Balance; public event PropertyChangedEventHandler PropertyChanged = delegate { }; public void RaisePropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged(this, new PropertyChangedEventArgs

How to raise PropertyChanged event without using string name

点点圈 提交于 2019-12-17 06:29:37
问题 It would be good to have ability to raise 'PropertyChanged' event without explicit specifying the name of changed property. I would like to do something like this: public string MyString { get { return _myString; } set { ChangePropertyAndNotify<string>(val=>_myString=val, value); } } private void ChangePropertyAndNotify<T>(Action<T> setter, T value) { setter(value); PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(setter

In MVVM model should the model implement INotifyPropertyChanged interface?

偶尔善良 提交于 2019-12-17 04:16:23
问题 I have clear idea about View and ViewModel in MVVM pattern. I am planning to implement MVVM pattern in my application. I'm facing an issue regarding the model. I have .xml file which is parsed and the information is displayed in the View. I need to be notified about the changes in the model for the first time only. From onwards on demand I need to be notified. So how to implement the model? Should I implement INotifyPropertyChanged interface in model class also? (I read that model should not

passing a string from one user control to a second user control via INotify wihtin MVVM

China☆狼群 提交于 2019-12-14 04:22:50
问题 I am having some issues with passing a string from one user control to a second user control via INotify. Within the view I have a listbox which is bound to a ObservableCollection of type string titled SearchHistory whenever a user types a value into a textbox which is within a user control I pass the value typed into the collection and display it within the listbox control ( somewhat of a history of terms entered). This works fine. I am now trying to select the listbox item and pass it back