mardi 4 décembre 2018

ComboBox IsChecked Binding not working in Data Template

I have a ComboBox with a Textblock and a Checkbox displayed to allow me to set a view model boolean property based off the checkbox.

View Code

<ComboBox HorizontalAlignment="Left" IsEditable="True" IsReadOnly="True" Text="-- Filter Columns --">
   <ComboBoxItem>
      <ComboBoxItem.ContentTemplate>
         <DataTemplate>
            <StackPanel Orientation="Horizontal">
               <TextBlock Text="Description"/>
               <CheckBox IsChecked="{Binding DescriptionHeaderVisibility}"/>
            </StackPanel>
         </DataTemplate>
      </ComboBoxItem.ContentTemplate>
   </ComboBoxItem>
</ComboBox>

View Model Property

 public bool DescriptionHeaderVisibility
 {
     get => _descriptionHeaderVisibility;
     set => Set(ref _descriptionHeaderVisibility, value);
 }

Useful information

  • I am using MVVM Light
  • If I do the exact same check box binding somewhere else on the page, it works and notifies my view model of the change.
  • Binding only does not work within the templated combo box

I am not sure why the binding is not working within the combo box template? Am I just missing something here that I don't know about? If I can get this binding to work properly the plan is to add another few rows of text blocks and check boxes all bound to different boolean properties in my view model.

Picture of drop down box

enter image description here




Aucun commentaire:

Enregistrer un commentaire