Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with Binding Dependency Property on a UserControl
    text
    copied!<p>I have a two userControls (IconUserControl &amp; DisplayUserControl), I'm having a problem with binding dependency properties, here's some detail:</p> <ul> <li>IconUserControl has a bool DP of IsDisplayShown</li> <li>DisplayUserControl has a bool DP of IsDisplayShown</li> </ul> <p>In the XAML I have:</p> <pre><code>&lt;local:DisplayUserControl x:Name="DisplayUserControl" IsDisplayShown="{Binding ElementName=IconUserControl, Path=IsDisplayShown, Converter={StaticResource DummyConverter}}" /&gt; &lt;local:IconUserControl x:Name="IconUserControl" /&gt; </code></pre> <p>When IconUserControl.IsDisplayShown is set to true, I can see in the DummyConverter this value getting passed, but it never sets DisplayUserControl.IsDisplayShown.</p> <p>However, if in the codebehind for the View I set <code>DisplayUserControl.IsDisplayShown = true;</code>, then it works fine.</p> <p>I have the DataContext for both UserControls set to "this" in the constructor. I've tried to fiddle with the "Mode" property of the binding.</p> <p>*Note: DummyConverter just returns the value, I only have this to confirm that the Binding is trying to work.</p> <p>What am I doing wrong?</p> <p>Edit:</p> <p>Here's the two DPs:</p> <pre><code>public bool IsDisplayShown { get { return (bool)GetValue(IsDisplayShownProperty); } set { SetValue(IsDisplayShownProperty, value); } } public static readonly DependencyProperty IsDisplayShownProperty = DependencyProperty.Register("IsDisplayShown", typeof(bool), typeof(IconUserControl), new UIPropertyMetadata(false)); public bool IsDisplayShown { get { return (bool)GetValue(IsDisplayShownProperty); } set { if (value) ShowOpenItems(); else HideOpenItems(); SetValue(IsDisplayShownProperty, value); } } public static readonly DependencyProperty IsDisplayShownProperty= DependencyProperty.Register("IsDisplayShown", typeof(bool), typeof(DisplayUserControl), new UIPropertyMetadata(false)); </code></pre>
 

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