Hi,
I am again stuck at creating dynamic controls i.e., second step in the image at the beginning (upon clicking of the checkbox I need to generate a new combo box with again some check boxes displaying the fields of that selected table) but in ViewModel only.
Below is my current code :-
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" x:Name="MultipleDatumUC">
<UserControl.Resources>
</UserControl.Resources>
<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}">
<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>
ViewModel :-
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 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
{
_allTablesCheckBoxContent = value;
OnPropertyChanged("AllTablesCheckBoxContent");
}
}
public string TableSelectedItem
{
get { return _tableSelectedItem; }
set
{
_tableSelectedItem …