This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi I want to replace the editted value if it does not pass the validation. Ex. At the QuickStart project in Samples solution. Original of Height property of Person class. set Set(ref _height, value, "Height"); I have changed as follows. set Set( ref _height, 500, "Height" ); When 1000000 is inputted to TestGrid, 500 is displayed at ReferenceGrid only. How can I update both TestGrid and ReferenceGrid?
|
|
|
Hmm, I don't think WPF data binding has any support for this: a bound property ignores change notifications resulting from the binding itself (partly to avoid infinite loops, but partly to avoid punishing the user by changing what he is typing while he is typing it). You could try setting NotifyOnSourceUpdated and listening for the SourceUpdated event, but I have a feeling this is not raised when the update is occurring due to the binding itself. Another possibility is in an appropriate event (e.g. LostFocus) to call BindingOperations.GetBindingExpression for the text box and the TextProperty DP, and call UpdateTarget on the resulting binding expression to force a refresh. (If the event you use is also the one that triggers the binding, you might need to defer this until the binding has done its stuff by using Dispatcher.Invoke with a Background priority.) Finally, you could try having the Set method defer the raising of the PropertyChanged event by queuing it as a dispatcher action. I.e. instead of calling OnPropertyChanged directly, call Dispatcher.CurrentDispatcher.BeginInvoke passing a DispatcherPriority of, say, Background and OnPropertyChanged as the delegate. I am not sure what the broader impact of this would be though. Please note I have not tested any of these options -- I would be interested to hear how you get on with them just for my own education! |
|
|
Thank you for your good comment and I'm sorry to late my reply. Following code works fine.
|
|