I have a two userControls (IconUserControl & DisplayUserControl), I'm having a problem with binding dependency properties, here's some detail:
- IconUserControl has a bool DP of IsDisplayShown
- DisplayUserControl has a bool DP of IsDisplayShown
In the XAML I have:
<local:DisplayUserControl
x:Name="DisplayUserControl"
IsDisplayShown="{Binding ElementName=IconUserControl, Path=IsDisplayShown, Converter={StaticResource DummyConverter}}" />
<local:IconUserControl
x:Name="IconUserControl" />
When IconUserControl.IsDisplayShown is set to true, I can see in the DummyConverter this value getting passed, but it never sets DisplayUserControl.IsDisplayShown.
However, if in the codebehind for the View I set DisplayUserControl.IsDisplayShown = true;
, then it works fine.
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.
*Note: DummyConverter just returns the value, I only have this to confirm that the Binding is trying to work.
What am I doing wrong?
Edit:
Here's the two DPs:
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));