Skip to content

Instantly share code, notes, and snippets.

@rousso
Last active December 13, 2015 22:49
Show Gist options
  • Save rousso/4987139 to your computer and use it in GitHub Desktop.
Save rousso/4987139 to your computer and use it in GitHub Desktop.
I was creating a WPF UserControl today which (among other things) was exposing a DependencyProperty for use in data binding. The problem I came across was that it didn't bind two-way by default and for a while I couldn't figure out either why nor what was the most slick way to go about it. So here is the trick in case anyone stumbles upon this p…
public const string myPropertyName = "myProperty";
public static readonly DependencyProperty myDependencyProperty =
DependencyProperty.Register(myPropertyName,
typeof(myPropertyType),
typeof(myUSerControl),
new FrameworkPropertyMetadata() { BindsTwoWayByDefault = true });
public myPropertyType myProperty
{
get { return (myPropertyType)GetValue(myDependencyProperty); }
set { SetValue(myDependencyProperty, value); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment