Your DP registration is incorrect. It should be like this:
public static readonly DependencyProperty MyTextProperty =
DependencyProperty.Register("MyText", typeof(string), typeof(BuyerInput),
new FrameworkPropertyMetadata
{
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
PropertyChangedCallback = OnMyTextChanged
});
public string MyText
{
get { return (string)GetValue(MyTextProperty); }
set { SetValue(MyTextProperty, value); }
}
private static void OnMyTextChanged(DependencyObject d,
DependencyPropertyChangedEventArgs args)
{
}
Explanation:
- OwneType and DP type parameters are swapped in your registration.
- DP wrappers are missing.
- And make DP to bind
TwoWay
. Default isOneWay
.
Binding also is not correct. In case you want to bind to TextBlock name MyTextBlock, it should be:
MyTextblock.SetBinding(TextBlock.TextProperty,
new Binding { Source = this,Path = new PropertyPath("MyText"),
Mode=BindingMode.TwoWay });
Update for comment -
I can't find FrameworkPropertyMetadata in WindowsStoreApp.
In case FrameworkPropertyMetadata
is not available on WinRT, use your PropertyMetadata
, that will work as well. But you need to set Mode
to TwoWay
on your binding. I have updated the binding above.