wsick / Fayde

Inspired by Silverlight; XAML engine using Javascript and rendering to the HTML5 Canvas.
MIT License
189 stars 27 forks source link

Combo Box [EVENTBINDING] Warning!!! #219

Open DheerajSaravagi opened 8 years ago

DheerajSaravagi commented 8 years ago

while using combo box selection change event its working fine but showing warning in console

[EVENTBINDING]: Could not find command target for event 'SelectionChanged'

below code is for reference

---------------------------<xaml code goes here >--------------------------

<ComboBox ItemsSource="{Binding Path=DropdownValues}"
                                       SelectedItem="{Binding Path=SelectedValue, Mode=TwoWay}"
                                       MinWidth="300"
                                       Height="30"
                                       Margin="5,0,0,0"
                                       DisplayMemberPath="Description"
                                       SelectedValuePath="Description"
                                       VerticalAlignment="Center"  
                                       IsDropDownOpen="{Binding Path=drpclose, Mode=TwoWay}"
                                       SelectionChanged ="{EventBinding Command={Binding DataContext.cmdDropdownValues_SelectedItemChanged, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}}" CommandParameter="{Binding}"                                       
                                       Visibility="{Binding  Path=ShowDropDown, Converter={StaticResource BooleanToVisibilityConverter}}"  />

----------------------------------<typescript code>------------------------------------
cmdDropdownValues_SelectedItemChanged: Fayde.MVVM.RelayCommand;

this.cmdDropdownValues_SelectedItemChanged = new Fayde.MVVM.RelayCommand(parm => this.DropdownValues_SelectedItemChanged(parm));

DropdownValues_SelectedItemChanged(e: any): void {

    }
BSick7 commented 8 years ago

It's warning you because your EventBinding is most likely incorrect. I would recommend against using SelectionChanged altogether. Since you already have a two-way binding for the selection, you could watch the change in your view model.

class VendorSearchViewModel ... {
...
  OnPropertyChanged(propertyName: string) {
    super.OnPropertyChanged(propertyName);
    if (propertyName === "SelectedValue") {
      //changed code
    }
  }
}
BSick7 commented 8 years ago

If you are still sold on using EventBinding, try changing to this:

(Remove the RelayCommand)

OnSelectedValueChanged(e: Fayde.IEventBindingArgs<Fayde.Controls.Primitives.SelectionChangedEventArgs >) {
  var value = e.args.NewValues[0];
  if (!value)
    return;

  var ParentObject = this.Criteria.GetValueAt(0);
  ParentObject.SelectedValue = value;
  if (value.Description == "Section" || value.Description == "AnswerStatus")
    ParentObject.Criteria = value.Key;
  else
    ParentObject.Criteria = value.Description;
}
SelectionChanged="{EventBinding Command={Binding DataContext.OnSelectedValueChanged, RelativeSource={RelativeSource ItemsControlParent}}, CommandParameter="{Binding}}"
DheerajSaravagi commented 8 years ago

We have used EventBinding so many places for many controls. This issue occurs only when we create new MVVM class object and assign to ContentControl for Page Navigation purpose. On page initialization stage it shows warning message in console. If we use only SelectionChanged={EventBinding functionName} then also it show warning message in above scenario. However this event and page functionality works fine once page is loaded.

BSick7 commented 8 years ago

It is possible that your DataContext may be swapping and causing the SelectedValue to change. During the DataContext swap, the EventBinding won't be able to find the callback as it is reporting. I wanted to warn the developer rather than have the developer confused why the event binding wasn't working.

This is why I recommend against using SelectionChanged. I built it to be compatible, but in your case, there is no reason to use it.