inotifypropertychanged

How to use INotifyPropertyChanged correctly in WPF/XAML

扶醉桌前 提交于 2019-12-01 08:14:42
问题 I have a custom object that I am trying to bind to a control. On that custom object I have implemented the INotifyPropertyChanged interface. I have successfully bound to my object and a property on that object. What I can't figure out is how to go from there. I've been working on this for 2 days now and I still cannot get it working. My assumption was that when I would change the property bound to the control that the value set in that property would then show up in the control. However, no

INotifyPropertyChange ~ PropertyChanged not firing when property is a collection and a new item is added to the collection

杀马特。学长 韩版系。学妹 提交于 2019-12-01 06:53:32
I have a class that implements the INotifyPropertyChanged interface. Some of the properties of the class are of type List. For example: public List<string> Answers { get { return _answers; } set { _answers = value; onPropertyChanged("Answers") } } ... private void onPropertyChanged(string propertyName) { if(this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } If I assign a new List<string> to Answer, then the PropertyChanged event fires as expected; but if I add a string string to the Answer list using the List Add method, then PropertyChanged

PropertyGrid doesn't notice properties changed in code?

那年仲夏 提交于 2019-12-01 03:29:52
I have a Winform application which uses colour to highlight certain things. I would like to allow the users to change 'their' colours. As an exercise, I thought I would create an instance of a class, with properties for the colours, and assign it to a property grid (to get a nice editor) . This seems to work fine, but I then thought I would like to let the users reset the colours (after they had fiddled and set them to 20 shades of beige) . So, I added a "reset" button to my form, which set the colour properties of my object back to the defaults. However, it seems that while it sets my object

Why can't I invoke PropertyChanged event from an Extension Method?

大城市里の小女人 提交于 2019-12-01 03:04:32
I've tried to code a class to avoid a method like "RaisePropertyChanged". I know that I can inherit from a class that has that implementation but in some cases I can't. I've tried with a Extension Method but Visual Studio complain. public static class Extension { public static void RaisePropertyChanged(this INotifyPropertyChanged predicate, string propertyName) { if (predicate.PropertyChanged != null) { predicate.PropertyChanged(propertyName, new PropertyChangedEventArgs(propertyName)); } } } It said: "The event ' System.ComponentModel.INotifyPropertyChanged.PropertyChanged' can only appear on

INotifyPropertyChanged and ObservableCollection WPF

你说的曾经没有我的故事 提交于 2019-11-30 23:23:59
Right now I have a calender that only displays one month(what ever month I pass in). I'm trying to let the user pick what month and year from a comboBox and have the calender update. I'm binding using observablecollection which I'm sort of familiar with. I have no clue how INotifyPropertyChanged works though. I've never used it before. Any help or advice is greatly appreciated. This is what I have so far: public class Schedule : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void Update(int propertyName) { if (propertyName != null) {

Why does OnPropertyChanged not work in Code Behind?

随声附和 提交于 2019-11-30 19:46:40
I'm trying to simplify some code by putting the ViewModel models into the code behind and binding the DataContext as "this", but it seems to work differently, in the following example: Why is it when the button is clicked, the TextBlock bound to "Message" does not change, even though OnPropertyChanged("Message") is called? XAML: <Window x:Class="TestSimple223.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <StackPanel HorizontalAlignment="Left"> <Button Content="Button"

INotifyPropertyChanged and ObservableCollection WPF

折月煮酒 提交于 2019-11-30 18:05:47
问题 Right now I have a calender that only displays one month(what ever month I pass in). I'm trying to let the user pick what month and year from a comboBox and have the calender update. I'm binding using observablecollection which I'm sort of familiar with. I have no clue how INotifyPropertyChanged works though. I've never used it before. Any help or advice is greatly appreciated. This is what I have so far: public class Schedule : INotifyPropertyChanged { public event

C#, WPF, MVVM and INotifyPropertyChanged

帅比萌擦擦* 提交于 2019-11-30 14:58:24
问题 I'm getting confused; I thought I understood INotifyPropertyChanged. I have a small WPF app with a frontend MainWindow class, a viewmodel in the middle and a model at the back. The model in my case is the Simulator class. The SimulatorViewModel is nearly transparent and just interfaces properties between MainWindow and Simulator. Simulator implements INotifyPropertyChanged and each property setter in Simulator calls the RaisePropertyChanged method: private string serialNumber; public string

Why is INotifyPropertyChanged not updating the variables in XAML?

青春壹個敷衍的年華 提交于 2019-11-30 14:20:25
问题 I want to simulate data changing in the model and having that data be reflected in XAML. As I understand I need to implement INotifyPropertyChanged. However, in the following code example, XAML displays the data from the customer only once but the date and time never changes. What do I have to change in the following example to make XAML continually display the current date and time as it changes in the model? In particular, I don't understand how the Binding would know when to check the

C#, WPF, MVVM and INotifyPropertyChanged

若如初见. 提交于 2019-11-30 13:45:43
I'm getting confused; I thought I understood INotifyPropertyChanged. I have a small WPF app with a frontend MainWindow class, a viewmodel in the middle and a model at the back. The model in my case is the Simulator class. The SimulatorViewModel is nearly transparent and just interfaces properties between MainWindow and Simulator. Simulator implements INotifyPropertyChanged and each property setter in Simulator calls the RaisePropertyChanged method: private string serialNumber; public string SerialNumber { get { return serialNumber; } set { serialNumber = value; RaisePropertyChanged(