Skip to content

WPF-833954-Updating sample code for checked items using IsCheckedMemberPathProperty #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions Samples/CheckItem-By-Property/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@
</local:ViewModel>
</Window.Resources>
<Grid>
<syncfusion:CheckListBox ItemsSource="{Binding VirtualCollection}"
<syncfusion:CheckListBox IsCheckedMemberPath="Enabled"
ItemsSource="{Binding VirtualCollection}"
GroupDescriptions="{Binding GroupDescriptions}"
DataContext="{StaticResource viewModel}"
DisplayMemberPath="Name"
Name="checkListBox"
Margin="20">

<!--Binding the IsChecked property from ViewModel-->
<syncfusion:CheckListBox.Resources>
<Style TargetType="syncfusion:CheckListBoxItem">
<Setter Property="IsChecked" Value="{Binding Mode=TwoWay, Path=IsChecked}"/>
</Style>
</syncfusion:CheckListBox.Resources>

<!--Disable the Virtualization to update the checked item-->
<syncfusion:CheckListBox.ItemsPanel>
<ItemsPanelTemplate>
Expand Down
22 changes: 19 additions & 3 deletions Samples/CheckItem-By-Property/Model/Model.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CheckItem_By_Property
{
//Model.cs
public class GroupItem
public class GroupItem : INotifyPropertyChanged
{
public string Name { get; set; }
public string GroupName { get; set; }
public bool IsChecked { get; set; }
}
private bool enabled;
public bool Enabled
{
get { return enabled; }
set
{
enabled = value;
OnPropertyChanged("Enabled");
}
}

public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
4 changes: 2 additions & 2 deletions Samples/CheckItem-By-Property/ViewModel/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ViewModel()
GroupDescriptions = new ObservableCollection<GroupDescription>();

VirtualCollection = new ObservableCollection<GroupItem>();
for (int i = 0; i < 1000; i++)
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
Expand All @@ -51,7 +51,7 @@ public ViewModel()
if (i % 2 == 0)
{
//Define a checked state for items
myitem.IsChecked = true;
myitem.Enabled = true;
}
VirtualCollection.Add(myitem);
}
Expand Down