Cannot pass/bind command to WPF user control

Я пытаюсь передать команду элементу пользовательского элемента управления WPF.

<UserControl x:Class="MyApp.MyControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <!-- shortened -->
    <Button Command="{Binding Command}">
        <Button.Content>
            <!-- shortened -->
        </Button.Content>
    </Button>
</UserControl>
public partial class MyControl : UserControl
{
   public static readonly DependencyProperty CommandProperty
      = DependencyProperty.Register("Command", 
                                           typeof(ICommand), typeof(MyControl));
   //shortened        
   public ICommand Command
   {
      get { return (ICommand)GetValue(CommandProperty); }
      set { SetValue(CommandProperty, value); }
   }
   //shortened
} 
<uc:MyControl Command="{Binding DoStuffCommand}" />  <!-- shortened -->

При нажатии на кнопку в пользовательском элементе управления ничего не происходит.
Когда я отлаживаю, свойство Command равно null.
Привязка команды к кнопке вне пользовательского элемента управления работает.
Что здесь происходит?

6
задан Indy9000 6 August 2013 в 12:05
поделиться