I have a custom control which has the following dependency property
public static readonly DependencyProperty PrintCommandProperty = DependencyProperty.Register(
"PrintCommand",
typeof(ICommand),
typeof(ExportPrintGridControl),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits));
public ICommand PrintCommand
{
get { return (ICommand)GetValue(PrintCommandProperty); }
set { throw new Exception("ReadOnly Dependency Property. Use Mode=OneWayToSource"); }
}
in the constructor of my control I am setting the default value of my property:
public MyControl()
{
this.SetValue(PrintCommandProperty, new DelegateCommand<object>(this.Print));
}
I am then trying to bind the property to my ViewModel, so that I can access the property and call the Print Command.
<controls:MyControl PrintCommand="{Binding PrintCommand, Mode=OneWayToSource}"/>
However binding in the XAML causes the property value to be set to null. If I remove the binding in XAML the default property value is set properly in the constructor of my control.
What is the correct way of getting my ViewModel to call the Print method of my control?