locked
Checkboxes and observablecollection RRS feed

  • Question

  • I have:

       
    public class Extra
      {
      public string Name {get;set;}
      }


    and I have

       
    public class CarViewModel
      {
       public ObservableCollection<Extra> OwningExtras { get; set; }
      public static IEnumerable<Extra> AllExtras
          {
            get
            {
              return Extra.GetAllExtras();
            }
          }
      public CarViewModel()
      {
      owningExtras=Extra.GetAvailableExtrasForCar(idCar)
      }
      }


    and CarView looks like:

    <UserControl x:Class="Repo.CarView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Repo="clr-namespace:Repo" Height="auto" Width="auto">
      
     
    
        <Grid >
         
          <ListBox ItemsSource="{Binding}" Name="lbExtras">
            <ListBox.ItemTemplate>
              <DataTemplate>
                <StackPanel Orientation="Horizontal">
                  <CheckBox"/> //How implement adding and removing Extras
                  <TextBlock Text="{Binding Path=Name}" />
            </StackPanel>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
      
        </Grid>
      </UserControl>


    And I wonder what connect to this.DataContext? And then how to notice that something is changed (Checked checkbox means that this car has this extra)

    Friday, July 2, 2010 10:32 AM

Answers

  • Hi macarthurwork,

    I think you should bind checkbox to custom type which makes it possible to not only show all available Extras but also edit the current collection.

    I wrote the following sample hopefully achieved what you want.

    If this does not work for you, or you have any further questions about it, feel free to let me know.

    Best regards,

    Min

     

    EditWindow.xaml

    <Window x:Class="Enum_ObsCollection.EditWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Enum_ObsCollection"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        Title="EditAvailableDays" Height="300" Width="300">
      <Grid Name="rootPanel">
        <StackPanel>
          <ListBox ItemsSource="{Binding IsDayAvailable}">
            <ListBox.ItemTemplate>
              <DataTemplate>
                <CheckBox Content="{Binding CurrentDay.Name}" IsChecked="{Binding IsAvailable}"/>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
        </StackPanel>
      </Grid>
    </Window>

    EditWindow.xaml.cs

    namespace Enum_ObsCollection
    {
      /// <summary>
      /// Interaction logic for Window1.xaml
      /// </summary>
      public partial class EditWindow : Window, INotifyPropertyChanged
      {
        protected void OnNotifyPropertyChanged(string p)
        {
          if (PropertyChanged != null)
          {
            PropertyChanged(this, new PropertyChangedEventArgs(p));
          }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    
        ObservableCollection<Day> _AvailableDays;
        public ObservableCollection<Day> AvailableDays
        {
          get { return _AvailableDays; }
          set
          {
            if (_AvailableDays != value)
            {
              _AvailableDays = value;
              OnNotifyPropertyChanged("AvailableDays");
            }
          }
        }
    
        ObservableCollection<DayBool> _IsDayAvailable;
        public ObservableCollection<DayBool> IsDayAvailable
        {
          get
          {
            if (_IsDayAvailable == null)
            {
              _IsDayAvailable= new ObservableCollection<DayBool>();
              IEnumerable<Day> allDays = Day.GetAllDays();
              foreach (var day in allDays)
              {
                _IsDayAvailable.Add(new DayBool(day, AvailableDays));
              }
            }
            return _IsDayAvailable; 
          }
          set
          {
            if (_IsDayAvailable != value)
            {
              _IsDayAvailable = value;
              OnNotifyPropertyChanged("IsDayAvailable");
            }
          }
        }
    
        public EditWindow()
        {
          InitializeComponent();
          rootPanel.DataContext = this;
        }
      }
    
      public class DayBool : INotifyPropertyChanged
      {
        protected void OnNotifyPropertyChanged(string p)
        {
          if (PropertyChanged != null)
          {
            PropertyChanged(this, new PropertyChangedEventArgs(p));
          }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    
        public DayBool() { }
    
        public DayBool(Day day, ObservableCollection<Day> targetDayCollection)
        {
          this.CurrentDay = day;
          this.TargetDayCollection = targetDayCollection;
    
    
        }
    
        ObservableCollection<Day> _TargetDayCollection;
        public ObservableCollection<Day> TargetDayCollection
        {
          get { return _TargetDayCollection; }
          set
          {
            if (_TargetDayCollection != value)
            {
              _TargetDayCollection = value;
              OnNotifyPropertyChanged("TargetDayCollection");
            }
          }
        }
    
        Day _CurrentDay;
        public Day CurrentDay
        {
          get { return _CurrentDay; }
          set
          {
            if (_CurrentDay != value)
            {
              _CurrentDay = value;
              OnNotifyPropertyChanged("CurrentDay");
            }
          }
        }
    
        bool _IsAvailable;
        public bool IsAvailable
        {
          get
          {
            string dayName = CurrentDay.Name;
            _IsAvailable = false;
            foreach (var targetDay in _TargetDayCollection)
            {
              if (dayName.Equals(targetDay.Name))
              {
                _IsAvailable = true;
              }
            }
            return _IsAvailable;
          }
          set
          {
            if (_IsAvailable != value)
            {
              if (value)
              {
                string dayName = CurrentDay.Name;
                Day dayToAdd = null;
                foreach (var targetDay in _TargetDayCollection)
                {
                  if (dayName.Equals(targetDay.Name))
                  {
                    dayToAdd = targetDay;
                  }
                }
                if (dayToAdd == null)
                {
                  _TargetDayCollection.Add(CurrentDay);
                }
              }
              else
              {
                string dayName = CurrentDay.Name;
                Day dayToRemove = null;
                foreach (var targetDay in _TargetDayCollection)
                {
                  if (dayName.Equals(targetDay.Name))
                  {
                    dayToRemove = targetDay;
                  }
                }
                if (dayToRemove != null)
                {
                  _TargetDayCollection.Remove(dayToRemove);
                }
              }
              _IsAvailable = value;
              OnNotifyPropertyChanged("IsAvailable");
            }
          }
        }
      }
    }
    

     MainWindow.xaml

    <Window x:Class="Enum_ObsCollection.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
      <Grid Name="rootPanel">
        <Grid.ColumnDefinitions>
          <ColumnDefinition></ColumnDefinition>
          <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Column="0">
          <TextBlock>Available Fruits:</TextBlock>
          <ListBox ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True">
            <ListBox.ItemTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding Name}"></TextBlock>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
        </StackPanel>
        <StackPanel Grid.Column="1">
          <TextBlock>Available Days:</TextBlock>
          <Button Name="Edit" HorizontalAlignment="Left" Click="Edit_Click">Edit</Button>
          <ListBox ItemsSource="{Binding AvailableDays}">
            <ListBox.ItemTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding Name}"></TextBlock>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
        </StackPanel>
      </Grid>
    </Window>
    

      MainWindow.xaml.cs

    namespace Enum_ObsCollection
    {
      public partial class MainWindow : Window
      {
        ObservableCollection<Fruit> fruits;
    
        public MainWindow()
        {
          InitializeComponent();
          fruits = getTestData();
          rootPanel.DataContext = fruits;
        }
    
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
          EditWindow EditWind = new EditWindow();
          ICollectionView view =CollectionViewSource.GetDefaultView(fruits);
          Fruit currentFruit = (Fruit)view.CurrentItem;
          EditWind.AvailableDays = currentFruit.AvailableDays;
          EditWind.Show();
        }
    
        ObservableCollection<Fruit> getTestData()
        {
          Fruit apple = new Fruit();
          apple.Name="Apple";
          apple.AvailableDays = new ObservableCollection<Day>(Day.GetAllDays());
    
          Fruit orange = new Fruit();
          orange.Name = "Orange ";
          orange.AvailableDays = new ObservableCollection<Day>(new List<Day>() { new Day(1), new Day(3) });
    
          ObservableCollection<Fruit> testData = new ObservableCollection<Fruit>() {apple, orange};
          return testData;
        }
      }
    
      public class Day
      {
        public string Name { get; set; }
    
        public Day()
        {
        }
    
        public Day(int i)
        {
          switch (i)
          {
            case 0:
              Name = "Sunday";
              break;
            case 1:
              Name = "Monday";
              break;
            case 2:
              Name = "Tuesday";
              break;
            case 3:
              Name = "Wednesday";
              break;
            case 4:
              Name = "Thursday";
              break;
            case 5:
              Name = "Friday";
              break;
            case 6:
              Name = "Saturday";
              break;
          }
        }
    
        public static IEnumerable<Day> GetAllDays()
        {
          List<Day> AllDays = new List<Day>();
          for (int i = 0; i < 7; i++)
          {
            AllDays.Add(new Day(i));
          }
          return AllDays;
        }
      }
    
      public class Fruit:INotifyPropertyChanged
      {
        protected void OnNotifyPropertyChanged(string p)
        {
          if (PropertyChanged != null)
          {
            PropertyChanged(this, new PropertyChangedEventArgs(p));
          }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    
        string _Name;
        public string Name
        {
          get { return _Name; }
          set
          {
            if (_Name != value)
            {
              _Name = value;
              OnNotifyPropertyChanged("Name");
            }
          }
        }
    
        ObservableCollection<Day> _AvailableDays;
        public ObservableCollection<Day> AvailableDays
        {
          get { return _AvailableDays; }
          set
          {
            if (_AvailableDays != value)
            {
              _AvailableDays = value;
              OnNotifyPropertyChanged("AvailableDays");
            }
          }
        }
      }
     
    }
    

     

    • Marked as answer by Min Zhu Thursday, July 8, 2010 6:19 AM
    Tuesday, July 6, 2010 6:45 AM

All replies

  •  

    You mean when someone click checkbox then it will be in collection and if someone uncheck then you need to remove from collection?


    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Friday, July 2, 2010 1:03 PM
  • Yes :)
    Friday, July 2, 2010 2:03 PM
  • Hi macarthurwork,

    I think you should bind checkbox to custom type which makes it possible to not only show all available Extras but also edit the current collection.

    I wrote the following sample hopefully achieved what you want.

    If this does not work for you, or you have any further questions about it, feel free to let me know.

    Best regards,

    Min

     

    EditWindow.xaml

    <Window x:Class="Enum_ObsCollection.EditWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Enum_ObsCollection"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        Title="EditAvailableDays" Height="300" Width="300">
      <Grid Name="rootPanel">
        <StackPanel>
          <ListBox ItemsSource="{Binding IsDayAvailable}">
            <ListBox.ItemTemplate>
              <DataTemplate>
                <CheckBox Content="{Binding CurrentDay.Name}" IsChecked="{Binding IsAvailable}"/>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
        </StackPanel>
      </Grid>
    </Window>

    EditWindow.xaml.cs

    namespace Enum_ObsCollection
    {
      /// <summary>
      /// Interaction logic for Window1.xaml
      /// </summary>
      public partial class EditWindow : Window, INotifyPropertyChanged
      {
        protected void OnNotifyPropertyChanged(string p)
        {
          if (PropertyChanged != null)
          {
            PropertyChanged(this, new PropertyChangedEventArgs(p));
          }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    
        ObservableCollection<Day> _AvailableDays;
        public ObservableCollection<Day> AvailableDays
        {
          get { return _AvailableDays; }
          set
          {
            if (_AvailableDays != value)
            {
              _AvailableDays = value;
              OnNotifyPropertyChanged("AvailableDays");
            }
          }
        }
    
        ObservableCollection<DayBool> _IsDayAvailable;
        public ObservableCollection<DayBool> IsDayAvailable
        {
          get
          {
            if (_IsDayAvailable == null)
            {
              _IsDayAvailable= new ObservableCollection<DayBool>();
              IEnumerable<Day> allDays = Day.GetAllDays();
              foreach (var day in allDays)
              {
                _IsDayAvailable.Add(new DayBool(day, AvailableDays));
              }
            }
            return _IsDayAvailable; 
          }
          set
          {
            if (_IsDayAvailable != value)
            {
              _IsDayAvailable = value;
              OnNotifyPropertyChanged("IsDayAvailable");
            }
          }
        }
    
        public EditWindow()
        {
          InitializeComponent();
          rootPanel.DataContext = this;
        }
      }
    
      public class DayBool : INotifyPropertyChanged
      {
        protected void OnNotifyPropertyChanged(string p)
        {
          if (PropertyChanged != null)
          {
            PropertyChanged(this, new PropertyChangedEventArgs(p));
          }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    
        public DayBool() { }
    
        public DayBool(Day day, ObservableCollection<Day> targetDayCollection)
        {
          this.CurrentDay = day;
          this.TargetDayCollection = targetDayCollection;
    
    
        }
    
        ObservableCollection<Day> _TargetDayCollection;
        public ObservableCollection<Day> TargetDayCollection
        {
          get { return _TargetDayCollection; }
          set
          {
            if (_TargetDayCollection != value)
            {
              _TargetDayCollection = value;
              OnNotifyPropertyChanged("TargetDayCollection");
            }
          }
        }
    
        Day _CurrentDay;
        public Day CurrentDay
        {
          get { return _CurrentDay; }
          set
          {
            if (_CurrentDay != value)
            {
              _CurrentDay = value;
              OnNotifyPropertyChanged("CurrentDay");
            }
          }
        }
    
        bool _IsAvailable;
        public bool IsAvailable
        {
          get
          {
            string dayName = CurrentDay.Name;
            _IsAvailable = false;
            foreach (var targetDay in _TargetDayCollection)
            {
              if (dayName.Equals(targetDay.Name))
              {
                _IsAvailable = true;
              }
            }
            return _IsAvailable;
          }
          set
          {
            if (_IsAvailable != value)
            {
              if (value)
              {
                string dayName = CurrentDay.Name;
                Day dayToAdd = null;
                foreach (var targetDay in _TargetDayCollection)
                {
                  if (dayName.Equals(targetDay.Name))
                  {
                    dayToAdd = targetDay;
                  }
                }
                if (dayToAdd == null)
                {
                  _TargetDayCollection.Add(CurrentDay);
                }
              }
              else
              {
                string dayName = CurrentDay.Name;
                Day dayToRemove = null;
                foreach (var targetDay in _TargetDayCollection)
                {
                  if (dayName.Equals(targetDay.Name))
                  {
                    dayToRemove = targetDay;
                  }
                }
                if (dayToRemove != null)
                {
                  _TargetDayCollection.Remove(dayToRemove);
                }
              }
              _IsAvailable = value;
              OnNotifyPropertyChanged("IsAvailable");
            }
          }
        }
      }
    }
    

     MainWindow.xaml

    <Window x:Class="Enum_ObsCollection.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
      <Grid Name="rootPanel">
        <Grid.ColumnDefinitions>
          <ColumnDefinition></ColumnDefinition>
          <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Column="0">
          <TextBlock>Available Fruits:</TextBlock>
          <ListBox ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True">
            <ListBox.ItemTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding Name}"></TextBlock>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
        </StackPanel>
        <StackPanel Grid.Column="1">
          <TextBlock>Available Days:</TextBlock>
          <Button Name="Edit" HorizontalAlignment="Left" Click="Edit_Click">Edit</Button>
          <ListBox ItemsSource="{Binding AvailableDays}">
            <ListBox.ItemTemplate>
              <DataTemplate>
                <TextBlock Text="{Binding Name}"></TextBlock>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
        </StackPanel>
      </Grid>
    </Window>
    

      MainWindow.xaml.cs

    namespace Enum_ObsCollection
    {
      public partial class MainWindow : Window
      {
        ObservableCollection<Fruit> fruits;
    
        public MainWindow()
        {
          InitializeComponent();
          fruits = getTestData();
          rootPanel.DataContext = fruits;
        }
    
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
          EditWindow EditWind = new EditWindow();
          ICollectionView view =CollectionViewSource.GetDefaultView(fruits);
          Fruit currentFruit = (Fruit)view.CurrentItem;
          EditWind.AvailableDays = currentFruit.AvailableDays;
          EditWind.Show();
        }
    
        ObservableCollection<Fruit> getTestData()
        {
          Fruit apple = new Fruit();
          apple.Name="Apple";
          apple.AvailableDays = new ObservableCollection<Day>(Day.GetAllDays());
    
          Fruit orange = new Fruit();
          orange.Name = "Orange ";
          orange.AvailableDays = new ObservableCollection<Day>(new List<Day>() { new Day(1), new Day(3) });
    
          ObservableCollection<Fruit> testData = new ObservableCollection<Fruit>() {apple, orange};
          return testData;
        }
      }
    
      public class Day
      {
        public string Name { get; set; }
    
        public Day()
        {
        }
    
        public Day(int i)
        {
          switch (i)
          {
            case 0:
              Name = "Sunday";
              break;
            case 1:
              Name = "Monday";
              break;
            case 2:
              Name = "Tuesday";
              break;
            case 3:
              Name = "Wednesday";
              break;
            case 4:
              Name = "Thursday";
              break;
            case 5:
              Name = "Friday";
              break;
            case 6:
              Name = "Saturday";
              break;
          }
        }
    
        public static IEnumerable<Day> GetAllDays()
        {
          List<Day> AllDays = new List<Day>();
          for (int i = 0; i < 7; i++)
          {
            AllDays.Add(new Day(i));
          }
          return AllDays;
        }
      }
    
      public class Fruit:INotifyPropertyChanged
      {
        protected void OnNotifyPropertyChanged(string p)
        {
          if (PropertyChanged != null)
          {
            PropertyChanged(this, new PropertyChangedEventArgs(p));
          }
        }
        public event PropertyChangedEventHandler PropertyChanged;
    
        string _Name;
        public string Name
        {
          get { return _Name; }
          set
          {
            if (_Name != value)
            {
              _Name = value;
              OnNotifyPropertyChanged("Name");
            }
          }
        }
    
        ObservableCollection<Day> _AvailableDays;
        public ObservableCollection<Day> AvailableDays
        {
          get { return _AvailableDays; }
          set
          {
            if (_AvailableDays != value)
            {
              _AvailableDays = value;
              OnNotifyPropertyChanged("AvailableDays");
            }
          }
        }
      }
     
    }
    

     

    • Marked as answer by Min Zhu Thursday, July 8, 2010 6:19 AM
    Tuesday, July 6, 2010 6:45 AM
  • Hi All,

     

    My case is also related to ObservableCollection and checkboxes. I couldn't find any posts related to this online, so I just post it here. My apologize if this is not the right location to post this.

    I got an observablecollection like this in viewmodel:

    private ObservableCollection<DataGroupViewModel> _dataGroupCollection;
            public ObservableCollection<DataGroupViewModel> DataGroupCollection
            {
                get { return _dataGroupCollection; }
                set
                {
                    if (value == _dataGroupCollection)
                        return;

                    _dataGroupCollection = value;

                    OnPropertyChanged(this, "DataGroupCollection");
                }
            }

    The DataGroupViewModel object is defined like this:

    public class DataGroupViewModel : INotifyPropertyChanged
        {
            public DataGroupViewModel(string name, ObservableCollection<Parameter> paramCollection)
            {
                _name = name;
                _parameterCollection = paramCollection;
            }

            private string _name;
            public string Name
            {
                get { return _name; }
                set
                {
                    if (value == _name)
                        return;

                    _name = value;

                    OnPropertyChanged(this, "Name");
                }
            }

            private ObservableCollection<Parameter> _parameterCollection;
            public ObservableCollection<Parameter> ParameterCollection
            {
                get { return _parameterCollection; }
                set
                {
                    if (value == _parameterCollection)
                        return;

                    _parameterCollection = value;

                    OnPropertyChanged(this, "ParameterCollection");
                }
            }

            public event PropertyChangedEventHandler PropertyChanged;

            private void OnPropertyChanged(object sender, string propertyName)
            {
                if (this.PropertyChanged != null)
                {
                    PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
                }
            }
        }

    And here is the parameter class:

     public class Parameter
        {
            public string Name { get; set; }
            public string Value { get; set; }
            public string Unit { get; set; }
        }

    I then want to bind this DataGroupCollection (ObservableCollection) to a ItemsSource in View (XAML) as:   

         <UserControl.Resources>   

           <DataTemplate x:Key="ParameterTemplate">
                <Grid HorizontalAlignment="Left" VerticalAlignment="Center" Background="DarkGray" MinWidth="255">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width=".02*" />
                        <ColumnDefinition Width=".70*" />
                        <ColumnDefinition Width=".03*" />
                        <ColumnDefinition Width=".25*" />
                    </Grid.ColumnDefinitions>
                    <CheckBox Grid.Column="0" Background="DarkGray"/>
                    <TextBlock Grid.Column="1" Text="{Binding Name}" HorizontalAlignment="Left" />
                    <TextBlock Grid.Column="2" Text="{Binding Value}" HorizontalAlignment="Center" Foreground="Blue" />
                    <TextBlock Grid.Column="3" Text="{Binding Unit}" HorizontalAlignment="Right" />
                </Grid>
            </DataTemplate>
            <DataTemplate x:Key="DataGroupTemplate">
                <local:GroupBox Header="{Binding Name}" HorizontalAlignment="Center" VerticalAlignment="Top" Padding="5" Margin="5" BorderBrush="Black" >
                    <StackPanel Orientation="Horizontal">
                        <ItemsControl Background="DarkGray" ItemsSource="{Binding ParameterCollection}" ItemTemplate="{StaticResource ParameterTemplate}"/>
                    </StackPanel>
                </local:GroupBox>
            </DataTemplate>
        </UserControl.Resources>

        <Grid x:Name="LayoutRoot" Background="Gray">
            <controls:TabControl Margin="5" Grid.Row="0" Background="DarkGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <controls:TabItem Header="ISS_EMU1" Background="Gray">
                    <ItemsControl ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="DarkGray" ItemsSource="{Binding DataGroupCollection}" ItemTemplate="{StaticResource DataGroupTemplate}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </controls:TabItem>

            </controls:TabControl>

    </Grid>

     

    This binding is working fine if the ObservableCollection DataGroupCollection doesn't changed, if it is changed, then checkbox attribute IsChecked also changed. I mean If user click on the checkbox to check it (IsChecked = true) and then the DataGroupCollection update, the IsChecked is set to false. Although I didn't bind to anythings.

    Well, a long post but my question is how to keep the IsChecked attribute of the checkboxes as it is. Not reset to false everytime the DataGroupCollection is updated.

     

    Thanks

     

     

    Friday, January 20, 2012 11:32 PM