Note that there are some explanatory texts on larger screens.

plurals
  1. POMVVM Binding to Textbox: Need to call GET after SET somehow
    primarykey
    data
    text
    <p>I am attempting to implement some simple validation on a textbox in MVVM</p> <pre><code> public string Property { get { if (App.PropertyStorageContainer != null) { return App.PropertyStorageContainer.Property; } else { return null; } } set { App.PropertyStorageContainer.Property = value; RaisePropertyChanged("Property"); } } </code></pre> <p>Then in my PropertyStorageContainer class I have</p> <pre><code>private string _property; public string Property { get { return App.PropertyStorageContainer.Property; } set { if(value meets some condition) { _property = value; } else { _property = someothervalue; } } } </code></pre> <p>.</p> <pre><code> &lt;TextBox Width="50" TextAlignment="Center" Text="{Binding Property, Mode=TwoWay, NotifyOnValidationError=True}" MaxLength="3"&gt;&lt;/TextBox&gt; </code></pre> <p>The point of this is to validate what goes in the box. Now if I set this value directly from my code then everything works as I would expect. It attempts to SET the value, then calls RaiseProperyChanged, then GET the value (which because of the validation may not be the same value that was entered originally). The final value retrieved does show up on the view, so I know TwoWay binding is working.</p> <p>The problem I have is when the input for SET comes from the bound XAML property / directy from user. In this case the SET method is called, the validation performed, but the GET never happens. This results in the unvalidated value remaining in the textbox on screen. </p> <p>My first question would be is this a bug or expected behavior? I can see how maybe they tried to save performance by removing that last GET when the input came straight from the user since there should be nothing new to GET. But if not then maybe the way I have it all setup is interfering with the GET being called. </p> <p>Second question is of course any suggestions for getting around this one. I've read a few suggestions for other methods of doing validation, but my program is already live on PROD and most of the changes being suggested involve a lot of rework for me so I am hoping to find a way to make it call GET any time the property is SET. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload