1

I have a button within a datatemplate whose Command is bound as follows,

<DataTemplate x:Key="ControlSectionChassisTemplate">
<controls:ButtonBadged x:Name="btnDeckLightOn" 
                                               x:Uid="/Infrastructure.GlobalizationLibrary/Resources/BarCodeServiceViewPumpOn"
                              Command="{Binding VmChassisControlData.DeckLightControlCommand,Mode=OneWay}"
                                         Margin="10,0,0,0"
                                         Style="{StaticResource BaseButtonBadgedStyle}">
</DataTemplate>

This DataTemplate is being set to a ContentControl as follows,

<ContentControl x:Name="CustomChassisContentControl"
                                        DataContext="{x:Bind ViewModel}"
                                        ContentTemplate="{StaticResource ControlSectionChassisTemplate}"
                                        Visibility="{x:Bind ViewModel.SelectedLocation,Mode=OneWay,Converter={StaticResource ParserToTemplateVisibilityConverter},ConverterParameter=Chassis}" />

Now with in the ViewModel constructor, I am creating the VmChassisControlData object as follows,

public class SomeViewModel
{
public VmBarCodeServiceChassisControlData VmChassisControlData { get; set; }
public SomeViewModel()
{
VmChassisControlData = _lifeTimeScope.Resolve<VmBarCodeServiceChassisControlData>(); //Creates an instance.
}
}

Now in VmBarCodeServiceChassisControlData I have the ICommand defined as follows,

public class VmBarCodeServiceChassisControlData : BindableBaseThreadSafe
{
public ICommand DeckLightControlCommand;
 public VmBarCodeServiceChassisControlData()
        {
            DeckLightControlCommand = new RelayCommand<bool>(TurnDeckLightOnOrOff);
        }
private async void TurnDeckLightOnOrOff(bool obj)
{
//Do something.
}
} 

Problem is when I run the code, it gives me a binding path error as follows. In fact the ICommand variable is present inside VmBarCodeServiceChassisControlData class. But don't know why it gives the error Please help.

Error: BindingExpression path error: 'DeckLightControlCommand' property not found on 'Application.ViewModel.Model.VmBarCodeServiceChassisControlData'. BindingExpression: Path='VmChassisControlData.DeckLightControlCommand' DataItem='Application.ViewModel.BarCodeServiceViewModel'; target element is 'Presentation.Common.Controls.ButtonBadged' (Name='btnDeckLightOn'); target property is 'Command' (type 'ICommand')

Just an FYI, within the same class VmBarCodeServiceChassisControlData I have an other property as follows, which is bound to a combobox and it just displays fine.

 public List<EnumLocalizer<HaloColors>> HaloColors
        {
            get
            {
                var HaloColorTypes = new List<EnumLocalizer<HaloColors>>();
                Enum.GetValues(typeof(HaloColors)).Cast<HaloColors>().ToList().ForEach(
                    dataType => HaloColorTypes.Add(new EnumLocalizer<HaloColors>() { Value = dataType }));
                return HaloColorTypes;
            }
        }
Clemens
  • 123,504
  • 12
  • 155
  • 268
nikhil
  • 1,578
  • 3
  • 23
  • 52

0 Answers0