views:

235

answers:

2

Hi, I'm creating a Toolbar with some buttons, and I want each button to execute an different command according to the ViewModel attached to it's DataContext, so I created if like this:

 public readonly DependencyProperty NewCommandProperty = DependencyProperty.Register(
   "NewCommand", typeof(ICommand),
   typeof(VirtueGridToolbar));

 public ICommand NewCommand
 {
  get
  {
   return (ICommand)GetValue(NewCommandProperty);
  }
  set
  {
   SetValue(NewCommandProperty, value);
  }
 }

 public GridToolbar()
 {
  InitializeComponent();
 }

and the xaml of the control is this:

<UserControl x:Class="Virtue.Modules.Library.Controls.GridToolbar"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
    <ToolBar Background="Transparent">
     <ToolBar.Items>
      <Button x:Name="NewButton"
        Width="25"
        Height="25"
        ToolTip="Novo"
        Command="{Binding NewCommand}">
       <Image Source="{DynamicResource NewLarge}" />
      </Button>
      <Button x:Name="EditButton"
        Width="25"
        Height="25"
        ToolTip="Editar">
       <Image Source="{DynamicResource EditLarge}" />
      </Button>
      <Button x:Name="DeleteButton"
        Width="25"
        Height="25"
        ToolTip="Excluir">
       <Image Source="{DynamicResource DeleteLarge}" />
      </Button>
      <Separator />
      <Button x:Name="SaveButton"
        Width="25"
        Height="25"
        ToolTip="Excluir">
       <Image Source="{DynamicResource SaveLarge}" />
      </Button>
     </ToolBar.Items>
    </ToolBar>
</UserControl>

But when I add the UserControl to another control and attribute the Command

<V:GridToolbar NewCommand="{Binding Path=New}" />

the command does not execute.

Any suggestions?

Tks, Diego

A: 

This is a duplicate of this answer (although I understand why it would not be obvious they are not related): http://stackoverflow.com/questions/337023/how-to-detect-broken-wpf-data-binding

HTH, Anderson

Anderson Imes
tks... using the binding diagnostics I found out that the problem was the property name. Solved my problem... :)
A: 

Poster deleted message

Salfab