NotifyPropertyChange makes me crazy
-
Hi! I have a quite complex binding structure. In the first place I have 4 classes. Class1 contains a List<Product> and Product contains several members. The other classes we can leave.. The UI has a Listbox(productListBox) where 2 members from Product are displayed. Works fine. Then, outside the listbox, I have one textbox for each of the product members and displays data from the selected listboxitem. I have set UpdateSourceTrigger=PropertyChanged. And that works fine as well. Seems like a nice working app. But now the tricky part: If I change the text in a TextBox I not only want the Listbox to update but also set a parameter anywhere to keep record if there has been a change. I need to use UpdateSourceTrigger=PropertyChanged otherwise if I save the data before the textbox lose focus I miss the changes. Have tried to write an own OnPropertyChanged event without success. With that I can set my parameter but then I lost the immediate listbox update, well, that part don't update at all then. Ideas? <TextBox Style="{StaticResource InfoTextBox}" Height="23" Name="textBox_Rev" DataContext="{Binding ElementName=productListbox, Path=SelectedItem}" Text="{Binding Path=ProductId, UpdateSourceTrigger=PropertyChanged}" //> public void OnPropertyChanged(PropertyChangedEventArgs e) { if (PropertyChanged != null) { PropertyChanged(this, e); IsChanged = true; // I also want this to be true if changes has occured }} In other words. I need a bool to see if data has changed when I close the app or want to load new data and request a save in case. Is there some way to sort of add a second OnPropertyChange or something? Help someone? :)
-
Hi! I have a quite complex binding structure. In the first place I have 4 classes. Class1 contains a List<Product> and Product contains several members. The other classes we can leave.. The UI has a Listbox(productListBox) where 2 members from Product are displayed. Works fine. Then, outside the listbox, I have one textbox for each of the product members and displays data from the selected listboxitem. I have set UpdateSourceTrigger=PropertyChanged. And that works fine as well. Seems like a nice working app. But now the tricky part: If I change the text in a TextBox I not only want the Listbox to update but also set a parameter anywhere to keep record if there has been a change. I need to use UpdateSourceTrigger=PropertyChanged otherwise if I save the data before the textbox lose focus I miss the changes. Have tried to write an own OnPropertyChanged event without success. With that I can set my parameter but then I lost the immediate listbox update, well, that part don't update at all then. Ideas? <TextBox Style="{StaticResource InfoTextBox}" Height="23" Name="textBox_Rev" DataContext="{Binding ElementName=productListbox, Path=SelectedItem}" Text="{Binding Path=ProductId, UpdateSourceTrigger=PropertyChanged}" //> public void OnPropertyChanged(PropertyChangedEventArgs e) { if (PropertyChanged != null) { PropertyChanged(this, e); IsChanged = true; // I also want this to be true if changes has occured }} In other words. I need a bool to see if data has changed when I close the app or want to load new data and request a save in case. Is there some way to sort of add a second OnPropertyChange or something? Help someone? :)
-
Hi! I have a quite complex binding structure. In the first place I have 4 classes. Class1 contains a List<Product> and Product contains several members. The other classes we can leave.. The UI has a Listbox(productListBox) where 2 members from Product are displayed. Works fine. Then, outside the listbox, I have one textbox for each of the product members and displays data from the selected listboxitem. I have set UpdateSourceTrigger=PropertyChanged. And that works fine as well. Seems like a nice working app. But now the tricky part: If I change the text in a TextBox I not only want the Listbox to update but also set a parameter anywhere to keep record if there has been a change. I need to use UpdateSourceTrigger=PropertyChanged otherwise if I save the data before the textbox lose focus I miss the changes. Have tried to write an own OnPropertyChanged event without success. With that I can set my parameter but then I lost the immediate listbox update, well, that part don't update at all then. Ideas? <TextBox Style="{StaticResource InfoTextBox}" Height="23" Name="textBox_Rev" DataContext="{Binding ElementName=productListbox, Path=SelectedItem}" Text="{Binding Path=ProductId, UpdateSourceTrigger=PropertyChanged}" //> public void OnPropertyChanged(PropertyChangedEventArgs e) { if (PropertyChanged != null) { PropertyChanged(this, e); IsChanged = true; // I also want this to be true if changes has occured }} In other words. I need a bool to see if data has changed when I close the app or want to load new data and request a save in case. Is there some way to sort of add a second OnPropertyChange or something? Help someone? :)
Would it be possible to change UpdateSourceTrigger to Explicit, wait for TextChanged events on your TextBox, do your custom logic, and then call UpdateSource() yourself?
Blog: http://windowsclientdevelopment.spaces.live.com FAQs: http://windowspresentationfoundation.wikispaces.com http://windowsmobile.wikispaces.com http://vsto.wikispaces.com
-
Would it be possible to change UpdateSourceTrigger to Explicit, wait for TextChanged events on your TextBox, do your custom logic, and then call UpdateSource() yourself?
Blog: http://windowsclientdevelopment.spaces.live.com FAQs: http://windowspresentationfoundation.wikispaces.com http://windowsmobile.wikispaces.com http://vsto.wikispaces.com