From e7e914501155b7a53524cf715b7fdbba83b8752e Mon Sep 17 00:00:00 2001
From: zerodev1200 <42404360+zerodev1200@users.noreply.github.com>
Date: Thu, 17 Oct 2024 23:28:25 +0900
Subject: [PATCH] add four DataGrid in sandbox-WpfApp
---
sandbox/WpfApp/MainWindow.xaml | 77 ++++++++++++++++-------
sandbox/WpfApp/MainWindow.xaml.cs | 101 ++++++++++++++++++++++++++++++
2 files changed, 156 insertions(+), 22 deletions(-)
diff --git a/sandbox/WpfApp/MainWindow.xaml b/sandbox/WpfApp/MainWindow.xaml
index e9d7411..79ac6a2 100644
--- a/sandbox/WpfApp/MainWindow.xaml
+++ b/sandbox/WpfApp/MainWindow.xaml
@@ -5,29 +5,62 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp"
mc:Ignorable="d"
- Title="MainWindow" Height="450" Width="800">
-
+
+
+
+
+
+
+
+
+
+
+
- -->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sandbox/WpfApp/MainWindow.xaml.cs b/sandbox/WpfApp/MainWindow.xaml.cs
index 8c476e2..519cdd4 100644
--- a/sandbox/WpfApp/MainWindow.xaml.cs
+++ b/sandbox/WpfApp/MainWindow.xaml.cs
@@ -87,6 +87,18 @@ namespace WpfApp
public ReactiveCommand AttachFilterCommand { get; } = new ReactiveCommand();
public ReactiveCommand ResetFilterCommand { get; } = new ReactiveCommand();
+ private ObservableList SourceList { get; } = [];
+ private IWritableSynchronizedView writableFilter;
+ private ISynchronizedView notWritableFilter;
+ public NotifyCollectionChangedSynchronizedViewList NotWritableNonFilterView { get; }
+ public NotifyCollectionChangedSynchronizedViewList NotWritableFilterView { get; }
+ public NotifyCollectionChangedSynchronizedViewList WritableNonFilterPersonView { get; }
+ public NotifyCollectionChangedSynchronizedViewList WritableFilterPersonView { get; }
+ public ReactiveCommand AttachFilterCommand2 { get; } = new ReactiveCommand();
+ public ReactiveCommand ResetFilterCommand2 { get; } = new ReactiveCommand();
+ public ReactiveCommand AttachFilterCommand3 { get; } = new ReactiveCommand();
+ public ReactiveCommand ResetFilterCommand3 { get; } = new ReactiveCommand();
+
public ViewModel()
{
observableList.Add(1);
@@ -156,8 +168,97 @@ namespace WpfApp
{
view.ResetFilter();
});
+
+ SourceList.Add(new() { Name = "a", Age = 1 });
+ SourceList.Add(new() { Name = "b", Age = 2 });
+ SourceList.Add(new() { Name = "c", Age = 3 });
+ SourceList.Add(new() { Name = "d", Age = 4 });
+ //NotWritable, NonFilter
+ NotWritableNonFilterView = SourceList.ToNotifyCollectionChanged();
+
+ //NotWritable, Filter
+ notWritableFilter = SourceList.CreateView(x => x);
+ NotWritableFilterView = notWritableFilter.ToNotifyCollectionChanged();
+
+ //Writable, NonFilter
+ WritableNonFilterPersonView = SourceList.ToWritableNotifyCollectionChanged();
+
+ //WritableNonFilterPersonView = SourceList.ToWritableNotifyCollectionChanged(x => x, (Person newView, Person original, ref bool setValue) =>
+ //{
+ // if (setValue)
+ // {
+ // // default setValue == true is Set operation
+ // original.Name = newView.Name;
+ // original.Age = newView.Age;
+
+ // // You can modify setValue to false, it does not set original collection to new value.
+ // // For mutable reference types, when there is only a single,
+ // // bound View and to avoid recreating the View, setting false is effective.
+ // // Otherwise, keeping it true will set the value in the original collection as well,
+ // // and change notifications will be sent to lower-level Views(the delegate for View generation will also be called anew).
+ // setValue = false;
+ // return original;
+ // }
+ // else
+ // {
+ // // default setValue == false is Add operation
+ // return new Person { Age = newView.Age, Name = newView.Name };
+ // }
+ //}, null);
+
+ //Writable, Filter
+ writableFilter = SourceList.CreateWritableView(x => x);
+ WritableFilterPersonView = writableFilter.ToWritableNotifyCollectionChanged();
+
+ //WritableFilterPersonView = writableFilter.ToWritableNotifyCollectionChanged((Person newView, Person original, ref bool setValue) =>
+ //{
+ // if (setValue)
+ // {
+ // // default setValue == true is Set operation
+ // original.Name = newView.Name;
+ // original.Age = newView.Age;
+
+ // // You can modify setValue to false, it does not set original collection to new value.
+ // // For mutable reference types, when there is only a single,
+ // // bound View and to avoid recreating the View, setting false is effective.
+ // // Otherwise, keeping it true will set the value in the original collection as well,
+ // // and change notifications will be sent to lower-level Views(the delegate for View generation will also be called anew).
+ // setValue = false;
+ // return original;
+ // }
+ // else
+ // {
+ // // default setValue == false is Add operation
+ // return new Person { Age = newView.Age, Name = newView.Name };
+ // }
+ //});
+
+ AttachFilterCommand2.Subscribe(_ =>
+ {
+ notWritableFilter.AttachFilter(x => x.Age % 2 == 0);
+ });
+
+ ResetFilterCommand2.Subscribe(_ =>
+ {
+ notWritableFilter.ResetFilter();
+ });
+
+ AttachFilterCommand3.Subscribe(_ =>
+ {
+ writableFilter.AttachFilter(x => x.Age % 2 == 0);
+ });
+
+ ResetFilterCommand3.Subscribe(_ =>
+ {
+ writableFilter.ResetFilter();
+ });
}
}
+ public class Person
+ {
+ public int? Age { get; set; }
+ public string? Name { get; set; }
+ }
public class WpfDispatcherCollection(Dispatcher dispatcher) : ICollectionEventDispatcher
{