I already tried these things out however I have done this by removing the class member "IsAllTablesCheckBoxChecked", taking data template of checkbox inside the comobobox and adding an Event Trigger by calling a dependency property that I discussed about in the previous article and my final code is up and running.
My code is as follows :-
xaml :-
<UserControl x:Class="MyProjectDemo.View.MultipleDatumFilter"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:interatComm="clr-namespace:InteractivityHelper"
mc:Ignorable="d"
MinHeight="600" MinWidth="800">
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel>
<TextBlock x:Name="txtAllTables" Text="Existing Tables" Height="25" Width="150" FontWeight="Bold" />
<ComboBox x:Name="cmbAllTables" Height="25" Width="175" ItemsSource="{Binding AllTables, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding SelectedTableContents, UpdateSourceTrigger=PropertyChanged}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<interatComm:InteractiveCommand Command="{Binding DelegateCmdCheckChange}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding AllTablesCheckBoxContent, UpdateSourceTrigger=PropertyChanged}" IsChecked="{Binding IsAllTablesCheckBoxChecked, Mode=TwoWay}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<interatComm:InteractiveCommand Command="{Binding Path=DataContext.DelegateCmdCheckChange,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ComboBox}}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel>
</StackPanel>
</Grid>
</UserControl>
View Model :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Windows.Data;
using Microsoft.Practices.Prism.Commands;
using MyProjectDemo.Classes;
using MySql.Data.MySqlClient;
using System.Data;
namespace MyProjectDemo.ViewModel
{
public class MultipleDatumFilterVM : INotifyPropertyChanged
{
#region Fields
private ObservableCollection<AllTablesCheckbox> _allTables;
private string _allTablesCheckBoxContent = string.Empty;
private string _tableSelectedItem = string.Empty;
private string _selectedTableContents = string.Empty;
private DelegateCommand<RoutedEventArgs> _DelegateCmdCheckChange = null;
#endregion
#region Public Variables
public MySqlConnection mySqlCon;
public CheckBox selectedTableChecked;
#endregion
#region Properties
public ObservableCollection<AllTablesCheckbox> AllTables
{
get { return _allTables; }
set
{
_allTables = value;
OnPropertyChanged("AllTables");
}
}
public string AllTablesCheckBoxContent
{
get { return _allTablesCheckBoxContent; }
set …