In a user control, you set CommandBindingas follows:
CommandTarget="{Binding ElementName=userControl11}"
If you look in the Output window while your program is running, you will see the following:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=userControl11'. BindingExpression:(no path); DataItem=null; target element is 'Button' (Name=''); target property is 'CommandTarget' (type 'IInputElement')
, userControl11. . , XAML, , , XAML , , '. , , .
, . :
public IInputElement CommandTarget
{
get { return (IInputElement)GetValue(CommandTargetProperty); }
set { SetValue(CommandTargetProperty, value); }
}
public static readonly DependencyProperty CommandTargetProperty =
DependencyProperty.Register("CommandTarget", typeof(IInputElement), typeof(UserControl1), new UIPropertyMetadata(null));
XAML :
<Button Content="Click"
Command="local:Commands.ClickCommand"
CommandTarget="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=CommandTarget}" />
, , . , UserControl1 , , . ( , , , " ", , , , .)
, .