1

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">
    <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

  • 1
    This looks like essentially the same question as this one (except with ICommand instead of String properties): http://stackoverflow.com/questions/1192100/how-to-achieve-databinding-with-an-user-control-in-wpf/ – Matt Hamilton Aug 10 '09 at 03:05
  • 1
    possible duplicate of [How to detect broken WPF Data binding?](http://stackoverflow.com/questions/337023/how-to-detect-broken-wpf-data-binding) –  Mar 08 '13 at 14:42

0 Answers0