Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF binding (dataGrid) OneWayToSource, UpdateSourceTrigger-Explicit - undesired source update
    primarykey
    data
    text
    <p>I have a problem with an undesired source update in the OneWayToSource, UpdateSourceTrigger.Explicit scenario</p> <p>Background: I have a DataGrid containing user data with a password column. I have derived the class DataGridPasswordColumn from DataGridTemplateColumn to</p> <p>Display some dummy masked data in the non-edit mode (e.g. ####) This is done by setting the CellTemplate to a TextBlock with a constant value:</p> <pre><code>FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(TextBlock)); frameworkElementFactory.SetValue(TextBlock.TextProperty, Properties.Resources.passwordEncrypted); CellTemplate = new DataTemplate { VisualTree = frameworkElementFactory }; </code></pre> <p>and to display two PasswordBox controls and an OK-button in the edit mode the following code is used:</p> <pre><code>FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof(PasswordEntry)); Binding bindingPassword = new Binding(propertyNamePassword) { Mode = BindingMode.OneWayToSource, // we only want the target to source binding get activated on explicit request (user clicks on 'OK' button) UpdateSourceTrigger = UpdateSourceTrigger.Explicit, // we need to catch and prevent the undesired source update NotifyOnSourceUpdated = true }; frameworkElementFactory.SetBinding(PasswordEntry.SelectedPasswordProperty, bindingPassword); CellEditingTemplate = new DataTemplate { VisualTree = frameworkElementFactory }; </code></pre> <p>PasswordEntry is a user control that </p> <ul> <li>Has a DependencyProperty named 'SelectedPasswordProperty'</li> <li><p>and waits for the user to click the OKButton and then does some validation (are the contents of the two PasswordBoxes identical?). If validation is fine, calls UpdateSource via the following code</p> <p>BindingExpression be = this.GetBindingExpression(SelectedPasswordProperty); if (be != null) { be.UpdateSource(); }</p></li> </ul> <p>Updating the source is fine.</p> <p>The problem is, that when the cell editing template (the PasswordEntry UserControl) is opened there is one undesired source update carrying a value of 'NULL'.</p> <p>I expected that when UpdateSourceTrigger = UpdateSourceTrigger.Explicit is used, there is no source update unless UpdateSource() is called.</p> <p>I have so far found no way to suppress this source update. I tried </p> <pre><code>NotifyOnSourceUpdated = true </code></pre> <p>with </p> <pre><code>private void PasswordEntry_SourceUpdated(object sender, DataTransferEventArgs dataTransferEventArgs) { ... // Cancel this source update dataTransferEventArgs.Handled = true; } </code></pre> <p>but it did not work, i.e. the source was still updated (with a NULL value).</p> <p>Is this a WPF bug? Has anybody had the same problem?</p>
    singulars
    1. This table or related slice is empty.
    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