7281

MultiBinding Converter in CheckBox.IsChecked not called

Question:

I have a custom combobox a multiselectioncombobox if you will,

the thing is the selections depend on an other collection. I tried to bind ComboBox.IsChecked property to MultiBinding Converter but the converter isn't called.

<DataTemplate> <StackPanel Orientation="Horizontal" x:Name="ItemStack" VirtualizingStackPanel.IsVirtualizing="False"> <CheckBox x:Name="CheckBoxItem" Command="{Binding SelectItem, RelativeSource={RelativeSource AncestorType={x:Type MultiSelectionComboBox}}}" CommandParameter="{Binding Key}" > <CheckBox.IsChecked> <MultiBinding Converter="{StaticResource MultiSelectionCommandConverter}" Mode="OneWay"> <Binding Path="Key"/> <Binding Path="SelectedItem" RelativeSource="{RelativeSource AncestorType={x:Type MultiSelectionComboBox}}" /> </MultiBinding> </CheckBox.IsChecked> </CheckBox> <TextBlock Text="{Binding DisplayText}"></TextBlock> </StackPanel> </DataTemplate>

and the converter is,

public class MultiSelectionCommandConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { ///stuff to do... } public object[] ConvertBack(object values, Type[] targetTypes, object parameter, CultureInfo culture) { return null; } }

any suggestions?

Answer1:

After trying out possibilities, I've found a work around. Still I'm not quite sure why this might work and the other won't.

I've changed my xaml to pass the whole object instead of the property. So the code looked liked this,

<DataTemplate> <StackPanel Orientation="Horizontal" x:Name="ItemStack" VirtualizingStackPanel.IsVirtualizing="False"> <CheckBox x:Name="CheckBoxItem" Command="{Binding SelectItem, RelativeSource={RelativeSource AncestorType={x:Type MultiSelectionComboBox}}}" CommandParameter="{Binding Key}" > <CheckBox.IsChecked> <MultiBinding Converter="{StaticResource MultiSelectionCommandConverter}" Mode="OneWay"> <Binding Path="Key"/> <Binding RelativeSource="{RelativeSource AncestorType={x:Type MultiSelectionComboBox}}" /> </MultiBinding> </CheckBox.IsChecked> </CheckBox> <TextBlock Text="{Binding DisplayText}"></TextBlock> </StackPanel> </DataTemplate>

and the converter is

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { string key = (string)values[0]; ObservableCollection<ListItem> selectedItems = (values[1] as MultiSelectionComboBox).SelectedItem; //do stuff return false; }

This is definitely not a desired solution but, this will do until i figure out the other reason.

Recommend

  • Trying to get a data from sql database: what to enter into textbox
  • knockout sammy.js navigation issue
  • Knockout, selectable table row
  • How to validate a List in a Primefaces dataTable - JSF
  • Disable validator via ajax
  • Laravel checkbox is not submitted to controller
  • JqGrid Select Box in a cell
  • import vb.net class library to vb6 project
  • Django's ClearableFileInput widget doesn't pass initial (“Currently”) value on submit
  • Correct “select all” checkbox with jQuery
  • Call to a member function roles() on null Laravel
  • Setting jsp checkbox with a value from database
  • Adding jQuery custom image tool tip to jsTree
  • rename javascript object in order to use a php array
  • symfony 2 phpunit - how to untick checkbox in form field
  • OnChange event handler not working
  • django tables2 checkbox
  • how to display data by using AJAX?
  • AngularJS - ngBind and Bootstrap Switch
  • posting multidimensional array from checkbox
  • Android Custom dialog inflating from layout - alignment issue
  • LINQ to Entities does not recognize the method 'System.String ToString()' method, and this
  • jQuery Slick Slider showing some empty slides
  • why does .next() give me 'undefined'
  • Null ImageView Reference
  • How to name a 'group' check box in Adobe Reader when wanting to fill form by FDF / XFDF
  • Add reference to ASP.NET 5 Class Library from Framework 4.5 Class Library Project
  • Drawing a Path in XAML (with binding) vs. C#. One works, one doesn't
  • Consuming a WCF service in a Java Client using wsHttpBinding
  • Angularjs pass function from Controller to Directive (or call controller function from directive) -
  • Copy to all folders batch file?
  • Force show.bind execution
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Lost migrations and Azure database is now out of sync
  • Get one-time binding to work for ng-if
  • Jenkins: How To Build multiple projects from a TFS repository?
  • How do I fake an specific browser client when using Java's Net library?
  • QuartzCore.framework for Mono Develop
  • Apache 2.4 - remove | delete | uninstall
  • Run Powershell script from inside other Powershell script with dynamic redirection to file