title: DependencyProperty in Custom Command
body: <p>I try to write a wrapper command class. I want use it like this</p>
  
  <pre><code>&lt;Button Content="Test"&gt;
    &lt;Button.Command&gt;
      &lt;local:FileOpenCommand Command="{Binding OpenFile}"/&gt;
    &lt;/Button.Command&gt;
  &lt;/Button&gt;
  </code></pre>
  
  <p>What I tried so far:</p>
  
  <pre><code>public class FileOpenCommand : FrameworkElement, ICommand
  {
      public static readonly DependencyProperty CommandProperty =
        DependencyProperty.RegisterAttached("Command",
          typeof(ICommand),
          typeof(FileOpenCommand),
          new FrameworkPropertyMetadata(CommandChanged)
          {
              DefaultValue = new RelayCommand(
                 (ob) =&gt; MessageBox.Show(ob.ToString()))
          });
  
      public ICommand Command
      {
          get { return (ICommand)this.GetValue(CommandProperty); }
          set { this.SetValue(CommandProperty, value); }
      }
  
      public static void CommandChanged(
           DependencyObject d, DependencyPropertyChangedEventArgs e) { /* ... */ }
  
      public bool CanExecute(object parameter) { /*...*/ }
  
      public event System.EventHandler CanExecuteChanged;
  
      public void Execute(object parameter)
      {
          var dlg = new OpenFileDialog();
          if (dlg.ShowDialog())
          {
              Command.Execute(dlg.FileName);
          }
      }
  }
  </code></pre>
  
  <p>This always shows the MessageBox from the <code>DefaultValue</code> command. The binding to <code>OpenFile</code> doesn't work. I get no BindingExpression errors but the <code>Openfile</code> Property is never called.</p>
  
  <p>Edit: The MainWindow Code</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
          DataContext = this;
      }
  
      public ICommand OpenFile
      {
          get { return new RelayCommand(
                   (obj) =&gt; MessageBox.Show("I want to see this!")); }
      }
  }
  </code></pre>