I'm binding the command property of two hyperlinks in my xaml to a command in the view (which is the datacontext):
<TextBlock>
<Hyperlink x:Name="linkCheckAll" Command="{Binding CheckAllZonesCommand}" CommandParameter="{Binding}">Check All</Hyperlink>
<TextBlock Margin="0,0,20,0"/>
<Hyperlink x:Name="linkUncheckAll" Command="{Binding UncheckAllZonesCommand}" CommandParameter="{Binding}">Uncheck All</Hyperlink>
</TextBlock>
Which looks like this:
I'm getting the following error when binding my commands:
System.Windows.Data Error: 40 : BindingExpression path error: 'CheckAllZonesCommand' property not found on 'object' ''ZonesView' (HashCode=56756307)'. BindingExpression:Path=CheckAllZonesCommand; DataItem='ZonesView' (HashCode=56756307); target element is 'Hyperlink' (HashCode=50738642); target property is 'Command' (type 'ICommand')
System.Windows.Data Error: 40 : BindingExpression path error: 'UncheckAllZonesCommand' property not found on 'object' ''ZonesView' (HashCode=56756307)'. BindingExpression:Path=UncheckAllZonesCommand; DataItem='ZonesView' (HashCode=56756307); target element is 'Hyperlink' (HashCode=53994596); target property is 'Command' (type 'ICommand')
"ZonesView" is my my dataContext, and I'm positive it contains the commands in question:
public class ZonesView : BaseViewModel
{
public static ICommand CheckAllZonesCommand = new DelegateCommand()
{
ExecuteMethod = new Action<object>(delegate(object o) { ((ZonesView)o).CheckAllZones(); }),
CanExecuteMethod = new Func<bool>(delegate() { return true; })
};
public void CheckAllZones()
{
foreach( CheckBox cb in ZonesCheckBoxes.Values.Where(cb => (cb.IsChecked != true) && cb.Name.Contains((String)ActiveTab.Header) ))
{
cb.IsChecked = true;
ZoneCheckBoxClicked(cb, null);
}
}
public static ICommand UncheckAllZonesCommand = new DelegateCommand()
{
ExecuteMethod = new Action<object>(delegate(object o) { ((ZonesView)o).UncheckAllZones(); }),
CanExecuteMethod = new Func<bool>(delegate() { return true; })
};
public void UncheckAllZones()
{
foreach( CheckBox cb in ZonesCheckBoxes.Values.Where(cb => (cb.IsChecked != false) && cb.Name.Contains((String)ActiveTab.Header)) )
{
cb.IsChecked = false;
ZoneCheckBoxClicked(cb, null);
}
}
From what I can tell, I've done everything right. The commands are public, they are the correct type, and the datacontext of the hyperlinks is correct (as you can tell by the BindingExpression path error message) - so what's going wrong?
I've tried making the Commands in the ZonesView class static, but it didn't change anything.