Note that there are some explanatory texts on larger screens.

plurals
  1. POaltering the value of a Dependency Property in WPF
    primarykey
    data
    text
    <p>We have a custom WPF control with multiple <code>TextBox</code>. Each <code>TextBox</code> has its <code>Text</code> property bound to a dependency property on our custom control (using the <code>generic.xaml</code> template). We would like to <strong>alter</strong> the value entered in the <code>TextBox</code> inside our custom control if the data provided is incorrect. We know we can use validation to accept or reject a value, but that would not meet our needs since we just want to slightly alter the value.</p> <p>For example, if the user enters <code>11</code> in a particular <code>TextBox</code> we want to update it to <code>2011</code>. Or we want to capitalize the value of one of the <code>TextBox</code> regardless of what the user enters.</p> <p>We cannot seem to find the proper WPF dependency property mechanism to perform this cleanly. We tried the CooerceCallback, but it will not update the <code>TextBox</code> that initiated the change in the dependency property. Other controls that are bound to that dependency property will get the modified value, but not the caller.</p> <p>One idea we had was to change the recommended default "property template" to do more than just <code>SetValue(property, value)</code>. So an example would be:</p> <pre><code>public string Year { get { return (string)GetValue(YearProperty);} { set { var newVal = UpdateValue(value); SetValue(YearProperty, newVal); } } </code></pre> <p>But that does not work as binding with dependency properties will NOT use the underlying .Net property but use SetValue() directly.</p> <p>If I have not confused everybody with this question, I would appreciate any help.</p> <p>Regards,</p> <p>Eric.</p> <p>PS: We are using .Net 3.5 SP1</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.
 

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