add four DataGrid in sandbox-WpfApp
This commit is contained in:
parent
62b959c2c2
commit
e7e9145011
@ -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">
|
||||
<!--<Grid>
|
||||
Title="MainWindow" Height="800" Width="800">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<ListView ItemsSource="{Binding ItemsView}"></ListView>
|
||||
<!-- 1つ目のグループ (上部に配置) -->
|
||||
<StackPanel Grid.Row="0" Grid.ColumnSpan="2" Orientation="Vertical">
|
||||
<ListBox ItemsSource="{Binding ItemsView}" />
|
||||
<Button Content="Add" Command="{Binding AddCommand}" />
|
||||
<Button Content="AddRange" Command="{Binding AddRangeCommand}" />
|
||||
<Button Content="Insert" Command="{Binding InsertAtRandomCommand}" />
|
||||
<Button Content="Remove" Command="{Binding RemoveAtRandomCommand}" />
|
||||
<Button Content="RemoveRange" Command="{Binding RemoveRangeCommand}" />
|
||||
<Button Content="Clear" Command="{Binding ClearCommand}" />
|
||||
<Button Content="Reverse" Command="{Binding ReverseCommand}" />
|
||||
<Button Content="Sort" Command="{Binding SortCommand}" />
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Column="1" Click="Button_Click">Insert</Button>
|
||||
<!-- 左上 (NotWritable, NonFilter) -->
|
||||
<GroupBox Grid.Row="1" Grid.Column="0" Header="NotWritable, NonFilter">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<DataGrid ItemsSource="{Binding NotWritableNonFilterView}" />
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
</Grid>-->
|
||||
<StackPanel>
|
||||
<ListBox ItemsSource="{Binding ItemsView}" />
|
||||
<Button Content="Add" Command="{Binding AddCommand}" />
|
||||
<Button Content="AddRange" Command="{Binding AddRangeCommand}" />
|
||||
<Button Content="Insert" Command="{Binding InsertAtRandomCommand}" />
|
||||
<Button Content="Remove" Command="{Binding RemoveAtRandomCommand}" />
|
||||
<Button Content="RemoveRange" Command="{Binding RemoveRangeCommand}" />
|
||||
<Button Content="Clear" Command="{Binding ClearCommand}" />
|
||||
<Button Content="Reverse" Command="{Binding ReverseCommand}" />
|
||||
<Button Content="Sort" Command="{Binding SortCommand}" />
|
||||
<Button Content="AttachFilter" Command="{Binding AttachFilterCommand}" />
|
||||
<Button Content="ResetFilter" Command="{Binding ResetFilterCommand}" />
|
||||
</StackPanel>
|
||||
<!-- 右上 (Writable, NonFilter) -->
|
||||
<GroupBox Grid.Row="1" Grid.Column="1" Header="Writable, NonFilter">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<DataGrid ItemsSource="{Binding WritableNonFilterPersonView}" />
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 左下 (NotWritable, Filter) -->
|
||||
<GroupBox Grid.Row="2" Grid.Column="0" Header="NotWritable, Filter">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<DataGrid ItemsSource="{Binding NotWritableFilterView}" />
|
||||
<Button Content="AttachFilter" Command="{Binding AttachFilterCommand2}" />
|
||||
<Button Content="ResetFilter" Command="{Binding ResetFilterCommand2}" />
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
<!-- 右下 (Writable, Filter) -->
|
||||
<GroupBox Grid.Row="2" Grid.Column="1" Header="Writable, Filter">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<DataGrid ItemsSource="{Binding WritableFilterPersonView}" />
|
||||
<Button Content="AttachFilter" Command="{Binding AttachFilterCommand3}" />
|
||||
<Button Content="ResetFilter" Command="{Binding ResetFilterCommand3}" />
|
||||
</StackPanel>
|
||||
</GroupBox>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
@ -87,6 +87,18 @@ namespace WpfApp
|
||||
public ReactiveCommand<Unit> AttachFilterCommand { get; } = new ReactiveCommand<Unit>();
|
||||
public ReactiveCommand<Unit> ResetFilterCommand { get; } = new ReactiveCommand<Unit>();
|
||||
|
||||
private ObservableList<Person> SourceList { get; } = [];
|
||||
private IWritableSynchronizedView<Person, Person> writableFilter;
|
||||
private ISynchronizedView<Person, Person> notWritableFilter;
|
||||
public NotifyCollectionChangedSynchronizedViewList<Person> NotWritableNonFilterView { get; }
|
||||
public NotifyCollectionChangedSynchronizedViewList<Person> NotWritableFilterView { get; }
|
||||
public NotifyCollectionChangedSynchronizedViewList<Person> WritableNonFilterPersonView { get; }
|
||||
public NotifyCollectionChangedSynchronizedViewList<Person> WritableFilterPersonView { get; }
|
||||
public ReactiveCommand<Unit> AttachFilterCommand2 { get; } = new ReactiveCommand<Unit>();
|
||||
public ReactiveCommand<Unit> ResetFilterCommand2 { get; } = new ReactiveCommand<Unit>();
|
||||
public ReactiveCommand<Unit> AttachFilterCommand3 { get; } = new ReactiveCommand<Unit>();
|
||||
public ReactiveCommand<Unit> ResetFilterCommand3 { get; } = new ReactiveCommand<Unit>();
|
||||
|
||||
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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user