From 8510db1a853415962b58ab6fee92bf1d09f44c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=20=D0=98=D0=B2=D0=B0=D1=88=D0=BA?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Sat, 26 Oct 2024 22:43:27 +0500 Subject: [PATCH] Add listview group expander --- .../Windows/MainGraph/FormulaViewModel.cs | 2 +- .../Windows/MainGraph/GraphView.xaml | 22 ++++++++++++++----- .../Windows/MainGraph/GraphView.xaml.cs | 7 ++++++ .../Windows/MainGraph/TableViewModel.cs | 2 +- .../Interfaces/IOneVariableFunction.cs | 3 +++ .../Models/Functions/FormulaFunction.cs | 19 ++++++++++++++-- .../Models/Functions/TableFunction.cs | 18 +++++++++++++-- 7 files changed, 61 insertions(+), 12 deletions(-) diff --git a/StructureHelper/Windows/MainGraph/FormulaViewModel.cs b/StructureHelper/Windows/MainGraph/FormulaViewModel.cs index dbfdc43..b2a3e64 100644 --- a/StructureHelper/Windows/MainGraph/FormulaViewModel.cs +++ b/StructureHelper/Windows/MainGraph/FormulaViewModel.cs @@ -89,7 +89,7 @@ namespace StructureHelper.Windows.MainGraph { if (Function is null) { - Function = new FormulaFunction(); + Function = new FormulaFunction(isUser: true); } Function.Name = Name; Function.Description = Description; diff --git a/StructureHelper/Windows/MainGraph/GraphView.xaml b/StructureHelper/Windows/MainGraph/GraphView.xaml index 6de161f..cfb841b 100644 --- a/StructureHelper/Windows/MainGraph/GraphView.xaml +++ b/StructureHelper/Windows/MainGraph/GraphView.xaml @@ -5,10 +5,13 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" xmlns:local="clr-namespace:StructureHelper.Windows.MainGraph" + Loaded="Window_Loaded" mc:Ignorable="d" d:DataContext="{d:DesignInstance local:GraphViewModel}" Title="StructureHelper" Height="700" - Width="1000" MinHeight="400" MinWidth="600"> + Width="1000" + MinHeight="400" + MinWidth="600"> @@ -18,14 +21,15 @@ - - + @@ -36,9 +40,15 @@ - - - + + + diff --git a/StructureHelper/Windows/MainGraph/GraphView.xaml.cs b/StructureHelper/Windows/MainGraph/GraphView.xaml.cs index 5603b4d..65e103e 100644 --- a/StructureHelper/Windows/MainGraph/GraphView.xaml.cs +++ b/StructureHelper/Windows/MainGraph/GraphView.xaml.cs @@ -23,6 +23,7 @@ namespace StructureHelper.Windows.MainGraph /// public partial class GraphView : Window { + private const string GROUP_FACTOR = "Group"; private GraphViewModel viewModel; public GraphView(GraphViewModel viewModel) { @@ -33,5 +34,11 @@ namespace StructureHelper.Windows.MainGraph public GraphView() : this(new GraphViewModel()) { } + private void Window_Loaded(object sender, RoutedEventArgs e) + { + CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(FunctionList.ItemsSource); + PropertyGroupDescription groupDescription = new PropertyGroupDescription(GROUP_FACTOR); + view.GroupDescriptions.Add(groupDescription); + } } } diff --git a/StructureHelper/Windows/MainGraph/TableViewModel.cs b/StructureHelper/Windows/MainGraph/TableViewModel.cs index 3dac3f0..1834980 100644 --- a/StructureHelper/Windows/MainGraph/TableViewModel.cs +++ b/StructureHelper/Windows/MainGraph/TableViewModel.cs @@ -102,7 +102,7 @@ namespace StructureHelper.Windows.MainGraph { if (Function is null) { - Function = new TableFunction(); + Function = new TableFunction(isUser: true); } Function.Name = Name; Function.Description = Description; diff --git a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs index 53a4d7b..95ad36e 100644 --- a/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs +++ b/StructureHelperCommon/Infrastructures/Interfaces/IOneVariableFunction.cs @@ -12,7 +12,10 @@ namespace StructureHelperCommon.Infrastructures.Interfaces { public interface IOneVariableFunction : ICloneable, ISaveable { + public const string GROUP_TYPE_1 = "System function"; + public const string GROUP_TYPE_2 = "User function"; public bool IsUser { get; set; } + public string Group { get; set; } public FunctionType Type { get; set; } public string Name { get; set; } public string Description { get; set; } diff --git a/StructureHelperCommon/Models/Functions/FormulaFunction.cs b/StructureHelperCommon/Models/Functions/FormulaFunction.cs index 7f6071f..ce5e857 100644 --- a/StructureHelperCommon/Models/Functions/FormulaFunction.cs +++ b/StructureHelperCommon/Models/Functions/FormulaFunction.cs @@ -1,4 +1,5 @@ -using StructureHelperCommon.Infrastructures.Enums; +using Microsoft.VisualBasic.ApplicationServices; +using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Interfaces; using System; using System.Collections.Generic; @@ -13,8 +14,11 @@ namespace StructureHelperCommon.Models.Functions public class FormulaFunction : IOneVariableFunction { private const string COPY = "copy"; + public const string GROUP_TYPE_1 = "System function"; + public const string GROUP_TYPE_2 = "User function"; public bool IsUser { get; set; } public FunctionType Type { get; set; } + public string Group { get; set; } public string Name { get; set; } public string Description { get ; set; } public List Table { get; set; } @@ -23,9 +27,19 @@ namespace StructureHelperCommon.Models.Functions public Guid Id => throw new NotImplementedException(); public ObservableCollection Functions { get; set; } - public FormulaFunction() + public FormulaFunction(bool isUser = false) { Type = FunctionType.FormulaFunction; + if (isUser) + { + IsUser = true; + Group = GROUP_TYPE_2; + } + else + { + IsUser = false; + Group = GROUP_TYPE_1; + } } public bool Check() @@ -43,6 +57,7 @@ namespace StructureHelperCommon.Models.Functions formulaFunction.Description = Description; formulaFunction.Formula = Formula; formulaFunction.IsUser = true; + formulaFunction.Group = GROUP_TYPE_2; return formulaFunction; } diff --git a/StructureHelperCommon/Models/Functions/TableFunction.cs b/StructureHelperCommon/Models/Functions/TableFunction.cs index 43b8fa3..6041409 100644 --- a/StructureHelperCommon/Models/Functions/TableFunction.cs +++ b/StructureHelperCommon/Models/Functions/TableFunction.cs @@ -13,10 +13,14 @@ namespace StructureHelperCommon.Models.Functions public class TableFunction : IOneVariableFunction { private const string COPY = "copy"; + public const string GROUP_TYPE_1 = "System function"; + public const string GROUP_TYPE_2 = "User function"; + private string name; public bool IsUser { get; set; } public FunctionType Type { get; set; } + public string Group { get; set; } public string Name { get => name; @@ -31,9 +35,19 @@ namespace StructureHelperCommon.Models.Functions public Guid Id => throw new NotImplementedException(); public ObservableCollection Functions { get; set; } - public TableFunction() + public TableFunction(bool isUser = false) { Type = FunctionType.TableFunction; + if (isUser) + { + IsUser = true; + Group = GROUP_TYPE_2; + } + else + { + IsUser = false; + Group = GROUP_TYPE_1; + } } public bool Check() @@ -53,7 +67,7 @@ namespace StructureHelperCommon.Models.Functions Table.ForEach(x => newTable.Add(x.Clone() as GraphPoint)); tableFunction.Table = newTable; tableFunction.IsUser = true; - + tableFunction.Group = GROUP_TYPE_2; return tableFunction; }