WPF Check

This commit is contained in:
neuecc 2024-02-22 18:39:06 +09:00
parent f5bf911c82
commit 170eecf922
3 changed files with 65 additions and 21 deletions

View File

@ -6,7 +6,7 @@
xmlns:local="clr-namespace:WpfApp"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<!--<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
@ -16,5 +16,9 @@
<Button Grid.Column="1" Click="Button_Click">Insert</Button>
</Grid>
</Grid>-->
<StackPanel>
<ListBox ItemsSource="{Binding ItemsView}" />
<Button Content="Clear" Command="{Binding ClearCommand}" />
</StackPanel>
</Window>

View File

@ -1,6 +1,8 @@
using ObservableCollections;
using R3;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
@ -22,38 +24,72 @@ namespace WpfApp
/// </summary>
public partial class MainWindow : Window
{
ObservableList<int> list;
public INotifyCollectionChangedSynchronizedView<int> ItemsView { get; set; }
//ObservableList<int> list;
//public INotifyCollectionChangedSynchronizedView<int> ItemsView { get; set; }
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
R3.WpfProviderInitializer.SetDefaultObservableSystem(x =>
{
Trace.WriteLine(x);
});
this.DataContext = new ViewModel();
list = new ObservableList<int>();
list.AddRange(new[] { 1, 10, 188 });
ItemsView = list.CreateSortedView(x => x, x => x, comparer: Comparer<int>.Default).ToNotifyCollectionChanged();
//list = new ObservableList<int>();
//list.AddRange(new[] { 1, 10, 188 });
//ItemsView = list.CreateSortedView(x => x, x => x, comparer: Comparer<int>.Default).ToNotifyCollectionChanged();
//BindingOperations.EnableCollectionSynchronization(ItemsView, new object());
}
//int adder = 99;
//private void Button_Click(object sender, RoutedEventArgs e)
//{
// ThreadPool.QueueUserWorkItem(_ =>
// {
// list.Add(adder++);
// });
//}
//protected override void OnClosed(EventArgs e)
//{
// ItemsView.Dispose();
//}
}
public class ViewModel
{
private ObservableList<int> observableList { get; } = new ObservableList<int>();
public INotifyCollectionChangedSynchronizedView<int> ItemsView { get; }
public ReactiveCommand<Unit> ClearCommand { get; } = new ReactiveCommand<Unit>();
public ViewModel()
{
observableList.Add(1);
observableList.Add(2);
ItemsView = observableList.CreateView(x => x).ToNotifyCollectionChanged();
BindingOperations.EnableCollectionSynchronization(ItemsView, new object());
}
int adder = 99;
private void Button_Click(object sender, RoutedEventArgs e)
{
ThreadPool.QueueUserWorkItem(_ =>
// var iii = 10;
ClearCommand.Subscribe(_ =>
{
list.Add(adder++);
// observableList.Add(iii++);
observableList.Clear();
});
}
protected override void OnClosed(EventArgs e)
{
ItemsView.Dispose();
}
}
}

View File

@ -9,6 +9,10 @@
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="R3Extensions.WPF" Version="1.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ObservableCollections\ObservableCollections.csproj" />
</ItemGroup>