Skip to content

Commit

Permalink
WPF Check
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Feb 22, 2024
1 parent f5bf911 commit 170eecf
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 19 deletions.
8 changes: 6 additions & 2 deletions sandbox/WpfApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:WpfApp"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<!--<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
Expand All @@ -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>
70 changes: 53 additions & 17 deletions sandbox/WpfApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();


BindingOperations.EnableCollectionSynchronization(ItemsView, new object());

//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;
//int adder = 99;

private void Button_Click(object sender, RoutedEventArgs e)
//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()
{
ThreadPool.QueueUserWorkItem(_ =>
observableList.Add(1);
observableList.Add(2);

ItemsView = observableList.CreateView(x => x).ToNotifyCollectionChanged();

BindingOperations.EnableCollectionSynchronization(ItemsView, new object());

// var iii = 10;
ClearCommand.Subscribe(_ =>
{
list.Add(adder++);
// observableList.Add(iii++);
observableList.Clear();
});
}

protected override void OnClosed(EventArgs e)
{
ItemsView.Dispose();
}
}
}
}
4 changes: 4 additions & 0 deletions sandbox/WpfApp/WpfApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 170eecf

Please sign in to comment.