forked from GuOrg/Gu.Wpf.DataGrid2D
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
106 changed files
with
6,044 additions
and
6,157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: ci | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: setup | ||
uses: actions/setup-dotnet@v3 | ||
- name: restore | ||
run: dotnet restore | ||
- name: build | ||
run: dotnet build --configuration Release --no-restore | ||
- name: test | ||
run: dotnet test --configuration Release --no-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
namespace Gu.Wpf.DataGrid2D.Demo | ||
{ | ||
using System.Windows.Controls; | ||
namespace Gu.Wpf.DataGrid2D.Demo; | ||
|
||
using System.Windows.Controls; | ||
|
||
public partial class AddRemoveView : UserControl | ||
public partial class AddRemoveView : UserControl | ||
{ | ||
public AddRemoveView() | ||
{ | ||
public AddRemoveView() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
this.InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,70 @@ | ||
namespace Gu.Wpf.DataGrid2D.Demo | ||
namespace Gu.Wpf.DataGrid2D.Demo; | ||
|
||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Windows.Input; | ||
|
||
public class AddRemoveViewModel | ||
{ | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Windows.Input; | ||
private int columns; | ||
|
||
public class AddRemoveViewModel | ||
public AddRemoveViewModel() | ||
{ | ||
private int columns; | ||
this.Data = new ObservableCollection<ObservableCollection<int>>(); | ||
|
||
public AddRemoveViewModel() | ||
{ | ||
this.Data = new ObservableCollection<ObservableCollection<int>>(); | ||
this.AddRowCommand = new RelayCommand(this.AddRow); | ||
this.AddColumnCommand = new RelayCommand(this.AddColumn); | ||
this.RemoveLastRowCommand = new RelayCommand(this.RemoveRow); | ||
this.RemoveLastColumnCommand = new RelayCommand(this.RemoveColumn); | ||
|
||
this.AddRowCommand = new RelayCommand(this.AddRow); | ||
this.AddColumnCommand = new RelayCommand(this.AddColumn); | ||
this.RemoveLastRowCommand = new RelayCommand(this.RemoveRow); | ||
this.RemoveLastColumnCommand = new RelayCommand(this.RemoveColumn); | ||
this.columns = 0; | ||
} | ||
|
||
this.columns = 0; | ||
} | ||
public ICommand AddRowCommand { get; } | ||
|
||
public ICommand AddRowCommand { get; } | ||
public ICommand AddColumnCommand { get; } | ||
|
||
public ICommand AddColumnCommand { get; } | ||
public ICommand RemoveLastColumnCommand { get; } | ||
|
||
public ICommand RemoveLastColumnCommand { get; } | ||
public ICommand RemoveLastRowCommand { get; } | ||
|
||
public ICommand RemoveLastRowCommand { get; } | ||
public ObservableCollection<ObservableCollection<int>> Data { get; } | ||
|
||
public ObservableCollection<ObservableCollection<int>> Data { get; } | ||
private void AddRow() | ||
{ | ||
var newRow = Enumerable.Range(0, this.columns).ToArray(); | ||
this.Data.Add(new ObservableCollection<int>(newRow)); | ||
} | ||
|
||
private void AddRow() | ||
private void AddColumn() | ||
{ | ||
foreach (var row in this.Data) | ||
{ | ||
var newRow = Enumerable.Range(0, this.columns).ToArray(); | ||
this.Data.Add(new ObservableCollection<int>(newRow)); | ||
row.Add(this.columns); | ||
} | ||
|
||
private void AddColumn() | ||
this.columns++; | ||
} | ||
|
||
private void RemoveColumn() | ||
{ | ||
if (this.columns > 0) | ||
{ | ||
foreach (var row in this.Data) | ||
{ | ||
row.Add(this.columns); | ||
row.RemoveAt(this.columns - 1); | ||
} | ||
|
||
this.columns++; | ||
} | ||
|
||
private void RemoveColumn() | ||
{ | ||
if (this.columns > 0) | ||
{ | ||
foreach (var row in this.Data) | ||
{ | ||
row.RemoveAt(this.columns - 1); | ||
} | ||
|
||
this.columns--; | ||
} | ||
this.columns--; | ||
} | ||
} | ||
|
||
private void RemoveRow() | ||
private void RemoveRow() | ||
{ | ||
var index = this.Data.Count - 1; | ||
if (index >= 0) | ||
{ | ||
var index = this.Data.Count - 1; | ||
if (index >= 0) | ||
{ | ||
this.Data.RemoveAt(index); | ||
} | ||
this.Data.RemoveAt(index); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
namespace Gu.Wpf.DataGrid2D.Demo | ||
{ | ||
using System; | ||
using System.Windows; | ||
namespace Gu.Wpf.DataGrid2D.Demo; | ||
|
||
using System; | ||
using System.Windows; | ||
|
||
public partial class App : Application | ||
public partial class App : Application | ||
{ | ||
protected override void OnStartup(StartupEventArgs e) | ||
{ | ||
protected override void OnStartup(StartupEventArgs e) | ||
if (e is { Args: { Length: 1 } args }) | ||
{ | ||
if (e is { Args: { Length: 1 } args }) | ||
{ | ||
var window = args[0]; | ||
this.StartupUri = new Uri($"Windows/{window}.xaml", UriKind.Relative); | ||
} | ||
|
||
base.OnStartup(e); | ||
var window = args[0]; | ||
this.StartupUri = new Uri($"Windows/{window}.xaml", UriKind.Relative); | ||
} | ||
|
||
base.OnStartup(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
namespace Gu.Wpf.DataGrid2D.Demo | ||
{ | ||
using System.Windows.Controls; | ||
namespace Gu.Wpf.DataGrid2D.Demo; | ||
|
||
using System.Windows.Controls; | ||
|
||
/// <summary> | ||
/// Interaction logic for Array2DView.xaml. | ||
/// </summary> | ||
public partial class Array2DView : UserControl | ||
/// <summary> | ||
/// Interaction logic for Array2DView.xaml. | ||
/// </summary> | ||
public partial class Array2DView : UserControl | ||
{ | ||
public Array2DView() | ||
{ | ||
public Array2DView() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
this.InitializeComponent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,76 @@ | ||
namespace Gu.Wpf.DataGrid2D.Demo | ||
namespace Gu.Wpf.DataGrid2D.Demo; | ||
|
||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Windows.Input; | ||
|
||
public class Array2DVm : INotifyPropertyChanged | ||
{ | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Windows.Input; | ||
private string? data; | ||
|
||
public class Array2DVm : INotifyPropertyChanged | ||
public Array2DVm() | ||
{ | ||
private string? data; | ||
this.Data2D = new[,] | ||
{ | ||
{ 1, 2 }, | ||
{ 3, 4 }, | ||
{ 5, 6 }, | ||
}; | ||
this.RowHeaders = new[] { "1", "2", "3" }; | ||
this.ColumnHeaders = new[] { "A", "B", "C" }; | ||
this.UpdateDataCommand = new RelayCommand(this.UpdateData); | ||
this.UpdateData(); | ||
} | ||
|
||
public Array2DVm() | ||
{ | ||
this.Data2D = new[,] | ||
{ | ||
{ 1, 2 }, | ||
{ 3, 4 }, | ||
{ 5, 6 }, | ||
}; | ||
this.RowHeaders = new[] { "1", "2", "3" }; | ||
this.ColumnHeaders = new[] { "A", "B", "C" }; | ||
this.UpdateDataCommand = new RelayCommand(this.UpdateData); | ||
this.UpdateData(); | ||
} | ||
public event PropertyChangedEventHandler? PropertyChanged; | ||
|
||
public event PropertyChangedEventHandler? PropertyChanged; | ||
public string[] RowHeaders { get; } | ||
|
||
public string[] RowHeaders { get; } | ||
public string[] ColumnHeaders { get; } | ||
|
||
public string[] ColumnHeaders { get; } | ||
public int[,] Data2D { get; } | ||
|
||
public int[,] Data2D { get; } | ||
public ICommand UpdateDataCommand { get; } | ||
|
||
public ICommand UpdateDataCommand { get; } | ||
public string? Data | ||
{ | ||
get => this.data; | ||
|
||
public string? Data | ||
private set | ||
{ | ||
get => this.data; | ||
|
||
private set | ||
if (value == this.data) | ||
{ | ||
if (value == this.data) | ||
{ | ||
return; | ||
} | ||
|
||
this.data = value; | ||
this.OnPropertyChanged(); | ||
return; | ||
} | ||
} | ||
|
||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) | ||
{ | ||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
this.data = value; | ||
this.OnPropertyChanged(); | ||
} | ||
} | ||
|
||
private static IEnumerable<IEnumerable<T>> Rows<T>(T[,] source) | ||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) | ||
{ | ||
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
|
||
private static IEnumerable<IEnumerable<T>> Rows<T>(T[,] source) | ||
{ | ||
for (int r = 0; r < source.GetLength(0); r++) | ||
{ | ||
for (int r = 0; r < source.GetLength(0); r++) | ||
var row = new List<T>(); | ||
for (int c = 0; c < source.GetLength(1); c++) | ||
{ | ||
var row = new List<T>(); | ||
for (int c = 0; c < source.GetLength(1); c++) | ||
{ | ||
row.Add(source[r, c]); | ||
} | ||
|
||
yield return row; | ||
row.Add(source[r, c]); | ||
} | ||
} | ||
|
||
private void UpdateData() | ||
{ | ||
this.Data = $"{{{string.Join(", ", Rows(this.Data2D).Select(x => $"{{{string.Join(", ", x)}}}"))}}}"; | ||
yield return row; | ||
} | ||
} | ||
|
||
private void UpdateData() | ||
{ | ||
this.Data = $"{{{string.Join(", ", Rows(this.Data2D).Select(x => $"{{{string.Join(", ", x)}}}"))}}}"; | ||
} | ||
} |
39 changes: 19 additions & 20 deletions
39
Gu.Wpf.DataGrid2D.Demo/CellEditingTemplateSelectorExample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
namespace Gu.Wpf.DataGrid2D.Demo | ||
{ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
namespace Gu.Wpf.DataGrid2D.Demo; | ||
|
||
public class CellEditingTemplateSelectorExample : DataTemplateSelector | ||
{ | ||
public DataTemplate? FirstTemplate { get; set; } | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
|
||
public DataTemplate? SecondTemplate { get; set; } | ||
public class CellEditingTemplateSelectorExample : DataTemplateSelector | ||
{ | ||
public DataTemplate? FirstTemplate { get; set; } | ||
|
||
public override DataTemplate? SelectTemplate(object item, DependencyObject container) | ||
public DataTemplate? SecondTemplate { get; set; } | ||
|
||
public override DataTemplate? SelectTemplate(object item, DependencyObject container) | ||
{ | ||
if (item is CellTemplateDemoClass democlass) | ||
{ | ||
if (item is CellTemplateDemoClass democlass) | ||
if (democlass.Value1 > 2) | ||
{ | ||
if (democlass.Value1 > 2) | ||
{ | ||
return this.FirstTemplate; | ||
} | ||
else | ||
{ | ||
return this.SecondTemplate; | ||
} | ||
return this.FirstTemplate; | ||
} | ||
else | ||
{ | ||
return this.SecondTemplate; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.