diff --git a/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControl.xaml b/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControl.xaml
index a6a53c2..1f3d779 100644
--- a/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControl.xaml
+++ b/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControl.xaml
@@ -37,5 +37,7 @@
+
+
diff --git a/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControl.xaml.cs b/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControl.xaml.cs
index 5797064..9a5d50b 100644
--- a/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControl.xaml.cs
+++ b/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControl.xaml.cs
@@ -23,7 +23,6 @@ public partial class DataGridAndListViewControl : UserControl
{
public DataGridAndListViewControl()
{
- DataContext = new DataGridTestViewModel();
InitializeComponent();
}
}
diff --git a/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControlAlternateBinding.xaml b/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControlAlternateBinding.xaml
new file mode 100644
index 0000000..de57426
--- /dev/null
+++ b/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControlAlternateBinding.xaml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ ListView Bound To TestCollectionView
+
+ DataGrid Bound To EditableTestCollectionView
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControlAlternateBinding.xaml.cs b/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControlAlternateBinding.xaml.cs
new file mode 100644
index 0000000..91c7315
--- /dev/null
+++ b/ExamplesAndTests/EditableDataGridTest/Controls/DataGridAndListViewControlAlternateBinding.xaml.cs
@@ -0,0 +1,29 @@
+using EditableDataGridTest.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace EditableDataGridTest.Controls
+{
+ ///
+ /// Interaction logic for DataGridAndListViewControl.xaml
+ ///
+ public partial class DataGridAndListViewControlAlternateBinding : UserControl
+ {
+ public DataGridAndListViewControlAlternateBinding()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/ExamplesAndTests/EditableDataGridTest/MainWindow.xaml b/ExamplesAndTests/EditableDataGridTest/MainWindow.xaml
index 39f4168..f41056c 100644
--- a/ExamplesAndTests/EditableDataGridTest/MainWindow.xaml
+++ b/ExamplesAndTests/EditableDataGridTest/MainWindow.xaml
@@ -7,6 +7,13 @@
mc:Ignorable="d"
Title="Editable DataGrid Test" Height="400" Width="600">
-
+
+
+
+
+
+
+
+
diff --git a/ExamplesAndTests/EditableDataGridTest/MainWindow.xaml.cs b/ExamplesAndTests/EditableDataGridTest/MainWindow.xaml.cs
index 3e2982c..bc39801 100644
--- a/ExamplesAndTests/EditableDataGridTest/MainWindow.xaml.cs
+++ b/ExamplesAndTests/EditableDataGridTest/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
-using System;
+using EditableDataGridTest.ViewModels;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -22,7 +23,8 @@ public partial class MainWindow : Window
{
public MainWindow()
{
- InitializeComponent();
+ DataContext = new DataGridTestViewModel();
+ InitializeComponent();
}
}
}
diff --git a/ExamplesAndTests/EditableDataGridTest/ViewModels/DataGridTestViewModel.cs b/ExamplesAndTests/EditableDataGridTest/ViewModels/DataGridTestViewModel.cs
index 3ce3826..143c3af 100644
--- a/ExamplesAndTests/EditableDataGridTest/ViewModels/DataGridTestViewModel.cs
+++ b/ExamplesAndTests/EditableDataGridTest/ViewModels/DataGridTestViewModel.cs
@@ -1,33 +1,88 @@
using Swordfish.NET.Collections;
using Swordfish.NET.Collections.Auxiliary;
using System;
+using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
+using System.Windows.Input;
+using System.Windows.Media.Animation;
namespace EditableDataGridTest.ViewModels
{
///
/// View model used as a source of items for both a ListView and a DataGrid
///
- public class DataGridTestViewModel
+ public class DataGridTestViewModel : INotifyPropertyChanged
{
private Random _random = new Random();
public DataGridTestViewModel()
{
- var randomItems = Enumerable.Range(0, 10).Select(i => new TestItem
+ TestCollection.PropertyChanged += (s, e) =>
{
- Label = _random.Next().ToString(),
- Value1 = _random.Next().ToString(),
- Value2 = _random.Next().ToString()
- });
+ switch (e.PropertyName)
+ {
+ case nameof(ConcurrentObservableCollection.CollectionView):
+ PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(nameof(TestCollectionView)));
+ break;
+ case nameof(ConcurrentObservableCollection.EditableCollectionView):
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(EditableTestCollectionView)));
+ break;
+ }
+ };
+
+ var randomItems = Enumerable.Range(0, 10).Select(i => GetRandomItem());
TestCollection.AddRange(randomItems);
}
+
+ private TestItem GetRandomItem() => new TestItem
+ {
+ Label = _random.Next().ToString(),
+ Value1 = _random.Next().ToString(),
+ Value2 = _random.Next().ToString()
+ };
+
+ private RelayCommandFactory _addRandomItemCommand = new RelayCommandFactory();
+ public ICommand AddRandomItemCommand => _addRandomItemCommand.GetCommand(() => TestCollection.Add(GetRandomItem()));
+
///
/// The source collection
///
public ConcurrentObservableCollection TestCollection { get; }
= new ConcurrentObservableCollection();
+
+ public IList TestCollectionView => TestCollection.CollectionView;
+ public IList EditableTestCollectionView => TestCollection.EditableCollectionView;
+
+ public event PropertyChangedEventHandler PropertyChanged;
}
+public class ExampleViewModel : INotifyPropertyChanged
+{
+ public ExampleViewModel()
+ {
+ TestCollection.PropertyChanged += (s, e) =>
+ {
+ switch (e.PropertyName)
+ {
+ case nameof(ConcurrentObservableCollection.CollectionView):
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(TestCollectionView)));
+ break;
+ case nameof(ConcurrentObservableCollection.EditableCollectionView):
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(EditableTestCollectionView)));
+ break;
+ }
+ };
+ }
+
+ public ConcurrentObservableCollection TestCollection { get; }
+ = new ConcurrentObservableCollection();
+
+ public IList TestCollectionView => TestCollection.CollectionView;
+ public IList EditableTestCollectionView => TestCollection.EditableCollectionView;
+
+ public event PropertyChangedEventHandler PropertyChanged;
+}
+
///
/// Test item used to populate the test collection
///
diff --git a/ExamplesAndTests/EditableDataGridTest/ViewModels/RelayCommand.cs b/ExamplesAndTests/EditableDataGridTest/ViewModels/RelayCommand.cs
new file mode 100644
index 0000000..923d900
--- /dev/null
+++ b/ExamplesAndTests/EditableDataGridTest/ViewModels/RelayCommand.cs
@@ -0,0 +1,317 @@
+using Swordfish.NET.Collections.Auxiliary;
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Input;
+
+namespace EditableDataGridTest.ViewModels
+{
+ ///
+ /// Preferable to use RelayCommandFactory to generate these
+ ///
+ public class RelayCommand : ICommand
+ {
+ #region Fields
+
+ protected readonly Action