Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit 1d9d18d

Browse files
committed
test demo
1 parent d9a2397 commit 1d9d18d

25 files changed

+1285
-238
lines changed

MvvmTestDemo/App.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Application.Resources>
99
<ResourceDictionary>
1010
<ResourceDictionary.MergedDictionaries>
11+
<!--<ResourceDictionary Source="pack://application:,,,/CookPopularControl;component/Themes/CookColors/GreenColor.xaml" />-->
1112
<ResourceDictionary Source="pack://application:,,,/CookPopularControl;component/Themes/DefaultPopularColor.xaml" />
1213
<ResourceDictionary Source="pack://application:,,,/CookPopularControl;component/Themes/DefaultPopularControl.xaml" />
1314
</ResourceDictionary.MergedDictionaries>

MvvmTestDemo/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using CookPopularCSharpToolkit.Communal;
2+
using CookPopularCSharpToolkit.Windows;
23
using System;
4+
using System.Collections.Generic;
35
using System.Collections.ObjectModel;
46
using System.Linq;
57
using System.Windows;

MvvmTestDemo/DemoModels/TreeViewModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,17 @@ public class TreeViewModel
2222

2323
public ObservableCollection<TreeViewModel> Children { get; set; }
2424
}
25+
26+
public class TreeViewModelStandard
27+
{
28+
public string Header { get; set; }
29+
30+
public int Level { get; set; }
31+
32+
public int ParentLevel { get; set; }
33+
34+
public bool IsParent { get; set; }
35+
36+
public ObservableCollection<TreeViewModelStandard> Children { get; set; }
37+
}
2538
}

MvvmTestDemo/DemoViewModels/TreeViewDemoViewModel.cs

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using MvvmTestDemo.DemoModels;
22
using Prism.Commands;
33
using Prism.Mvvm;
4+
using System.Collections.Generic;
45
using System.Collections.ObjectModel;
56
using System.Windows;
67
using System.Windows.Controls;
@@ -17,7 +18,7 @@ namespace MvvmTestDemo.DemoViewModels
1718
{
1819
public class TreeViewDemoViewModel : BindableBase
1920
{
20-
public ObservableCollection<TreeViewModel> TreeViewDemoItems { get; set; }
21+
public ObservableCollection<TreeViewModelStandard> TreeViewDemoItems { get; set; }
2122

2223
public DelegateCommand<RoutedPropertyChangedEventArgs<object>> TreeViewSelectedItemCommand => new DelegateCommand<RoutedPropertyChangedEventArgs<object>>(OnTreeViewSelectedItemChanged);
2324
public DelegateCommand TreeViewDoubleClickCommand => new DelegateCommand(OnTreeViewDoubleClick);
@@ -31,53 +32,87 @@ public TreeViewDemoViewModel()
3132

3233
private void InitData()
3334
{
34-
TreeViewDemoItems = new ObservableCollection<TreeViewModel>();
35-
for (int i = 1; i < 6; i++)
35+
var models = new List<TreeViewModelStandard>();
36+
for (int i = 0; i < 5; i++)
3637
{
37-
TreeViewDemoItems.Add(new TreeViewModel
38-
{
39-
Header = $"Chance{i}",
40-
HeaderIndex = i - 1,
41-
Level = 1,
42-
Root = null,
43-
}) ;
38+
models.Add(new TreeViewModelStandard { Header = $"Chance{i + 1}", Level = 1, ParentLevel = 0, IsParent = true });
39+
models.Add(new TreeViewModelStandard { Header = $"Chance{i + 1}", Level = 2, ParentLevel = 1, IsParent = false });
40+
models.Add(new TreeViewModelStandard { Header = $"Chance{i + 1}", Level = 3, ParentLevel = 2, IsParent = false });
4441
}
4542

46-
47-
for (int i = 1; i < 6; i++)
43+
TreeViewDemoItems = new ObservableCollection<TreeViewModelStandard>();
44+
foreach (var model in models)
4845
{
49-
TreeViewDemoItems[i - 1].Children = new ObservableCollection<TreeViewModel>();
50-
for (int j = 1; j < 6; j++)
46+
model.Children = new ObservableCollection<TreeViewModelStandard>();
47+
model.Children.AddRange(FindChild(model));
48+
49+
if (model.ParentLevel == 0) //判断是否为根节点
5150
{
52-
TreeViewDemoItems[i - 1].Children.Add(new TreeViewModel
53-
{
54-
Header = $"Chance{j}",
55-
HeaderIndex = j - 1,
56-
Level = 2,
57-
Root = TreeViewDemoItems[i - 1],
58-
});
51+
TreeViewDemoItems.Add(model);
5952
}
6053
}
6154

62-
for (int i = 1; i < 6; i++)
55+
IEnumerable<TreeViewModelStandard> FindChild(TreeViewModelStandard node)
6356
{
64-
for (int j = 1; j < 6; j++)
57+
foreach (var model in models)
6558
{
66-
TreeViewDemoItems[i - 1].Children[j - 1].Children = new ObservableCollection<TreeViewModel>();
67-
for (int h = 1; h < 6; h++)
68-
{
69-
TreeViewDemoItems[i - 1].Children[j - 1].Children.Add(new TreeViewModel
70-
{
71-
Header = $"Chance{h}",
72-
HeaderIndex = h - 1,
73-
Level = 3,
74-
Root = TreeViewDemoItems[i - 1].Children[j - 1],
75-
});
76-
}
59+
if(model.ParentLevel == node.Level)
60+
yield return model;
7761
}
62+
63+
yield break;
7864
}
7965
}
8066

67+
private void InitData1()
68+
{
69+
//TreeViewDemoItems = new ObservableCollection<TreeViewModel>();
70+
//for (int i = 1; i < 6; i++)
71+
//{
72+
// TreeViewDemoItems.Add(new TreeViewModel
73+
// {
74+
// Header = $"Chance{i}",
75+
// HeaderIndex = i - 1,
76+
// Level = 1,
77+
// Root = null,
78+
// }) ;
79+
//}
80+
81+
82+
//for (int i = 1; i < 6; i++)
83+
//{
84+
// TreeViewDemoItems[i - 1].Children = new ObservableCollection<TreeViewModel>();
85+
// for (int j = 1; j < 6; j++)
86+
// {
87+
// TreeViewDemoItems[i - 1].Children.Add(new TreeViewModel
88+
// {
89+
// Header = $"Chance{j}",
90+
// HeaderIndex = j - 1,
91+
// Level = 2,
92+
// Root = TreeViewDemoItems[i - 1],
93+
// });
94+
// }
95+
//}
96+
97+
//for (int i = 1; i < 6; i++)
98+
//{
99+
// for (int j = 1; j < 6; j++)
100+
// {
101+
// TreeViewDemoItems[i - 1].Children[j - 1].Children = new ObservableCollection<TreeViewModel>();
102+
// for (int h = 1; h < 6; h++)
103+
// {
104+
// TreeViewDemoItems[i - 1].Children[j - 1].Children.Add(new TreeViewModel
105+
// {
106+
// Header = $"Chance{h}",
107+
// HeaderIndex = h - 1,
108+
// Level = 3,
109+
// Root = TreeViewDemoItems[i - 1].Children[j - 1],
110+
// });
111+
// }
112+
// }
113+
//}
114+
}
115+
81116
private void OnTreeViewSelectedItemChanged(RoutedPropertyChangedEventArgs<object> e)
82117
{
83118
var treeView = e.Source as TreeView;

MvvmTestDemo/DemoViews/FieldsDemo.xaml

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<UserControl x:Class="MvvmTestDemo.DemoViews.FieldsDemo"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:behavior="http://schemas.microsoft.com/xaml/behaviors"
45
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
56
xmlns:local="clr-namespace:MvvmTestDemo.DemoViews"
67
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
78
xmlns:pc="https://Chance.CookPopularControl/2021/xaml"
89
xmlns:pt="https://Chance.CookPopularCSharpToolkit/2021/xaml"
9-
xmlns:behavior="http://schemas.microsoft.com/xaml/behaviors"
1010
mc:Ignorable="d"
11-
d:DesignHeight="450"
11+
d:DesignHeight="850"
1212
d:DesignWidth="800"
1313
DataContext="{Binding RelativeSource={RelativeSource Self}}">
1414

@@ -23,8 +23,8 @@
2323
Style="{StaticResource DefaultTextBoxStyle}" />
2424
<TextBox Width="300" Height="34"
2525
BorderThickness="1"
26-
Margin="20,0"
2726
IsEnabled="False"
27+
Margin="20,0"
2828
Style="{StaticResource AddClearButtonTextBoxStyle}" />
2929
<TextBox Width="300" Height="34"
3030
BorderThickness="1"
@@ -43,7 +43,8 @@
4343
Margin="20,0"
4444
Style="{StaticResource ValidationAddClearButtonTextBoxStyle}">
4545
<TextBox.Text>
46-
<Binding Mode="TwoWay" Path="TextContent2" UpdateSourceTrigger="PropertyChanged" NotifyOnTargetUpdated="True" NotifyOnValidationError="True">
46+
<Binding Mode="TwoWay" NotifyOnTargetUpdated="True" NotifyOnValidationError="True"
47+
Path="TextContent2" UpdateSourceTrigger="PropertyChanged">
4748
<Binding.ValidationRules>
4849
<pt:RegularPatternValidationRule RegularPattern="Chinese" ValidatesOnTargetUpdated="True" />
4950
</Binding.ValidationRules>
@@ -52,6 +53,15 @@
5253
</TextBox>
5354
</WrapPanel>
5455

56+
<TextBlock Text="RichTextBox:"
57+
FontSize="20" FontWeight="DemiBold"
58+
Margin="0,0,0,10" />
59+
<WrapPanel>
60+
<RichTextBox Width="300" Height="300"
61+
BorderThickness="1"
62+
Style="{StaticResource DefaultRichTextBoxStyle}" />
63+
</WrapPanel>
64+
5565
<TextBlock Text="NumericUpDown:"
5666
FontSize="20" FontWeight="DemiBold"
5767
Margin="0,30,0,10" />
@@ -60,35 +70,40 @@
6070
<pc:NumericUpDown Width="200" Height="34"
6171
Maximum="20"
6272
Margin="20,0"
63-
Increment="0.5" IsShowUpDownButton="False" />
73+
Increment="0.5" IsShowUpDownButton="False" />
6474
<pc:NumericUpDown Width="200" Height="34"
6575
Maximum="10"
6676
Increment="0.5" ValueFormat="F4" />
6777
<pc:NumericUpDown Width="200" Height="34"
6878
Margin="0,20"
6979
Style="{StaticResource NumericUpDownAddClearButtonStyle}" />
70-
<pc:NumericUpDown x:Name="num5" Width="200" Height="34" Minimum="0"
71-
Margin="20" ValueChanged="NumericUpDown_ValueChanged"
80+
<pc:NumericUpDown x:Name="num5"
81+
Width="200" Height="34"
82+
Minimum="0"
83+
Margin="20"
84+
ValueChanged="NumericUpDown_ValueChanged"
7285
Style="{StaticResource NumericUpDownAddClearButtonStyle}">
7386
<behavior:Interaction.Triggers>
7487
<behavior:EventTrigger EventName="ValueChanged">
75-
<behavior:InvokeCommandAction Command="{Binding Sure123Command}" CommandParameter="{Binding ElementName=num5,Path=Value}"/>
88+
<behavior:InvokeCommandAction Command="{Binding Sure123Command}" CommandParameter="{Binding ElementName=num5, Path=Value}" />
7689
</behavior:EventTrigger>
7790
</behavior:Interaction.Triggers>
7891
<pc:NumericUpDown.Value>
79-
<Binding Mode="TwoWay" Path="NumericValue" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
92+
<Binding Mode="TwoWay" NotifyOnValidationError="True" Path="NumericValue"
93+
UpdateSourceTrigger="PropertyChanged">
8094
<Binding.ValidationRules>
81-
<pt:RegularPatternValidationRule RegularPattern="NotNegativeInt" ErrorMessage="Please Input Positive Number" ValidatesOnTargetUpdated="True" />
95+
<pt:RegularPatternValidationRule ErrorMessage="Please Input Positive Number" RegularPattern="NotNegativeInt" ValidatesOnTargetUpdated="True" />
8296
<!--<pt:RangeValueValidationRule ErrorMessage="{x:Null}" MaxValue="10" MinValue="-5" ValidatesOnTargetUpdated="True" />-->
8397
</Binding.ValidationRules>
8498
</Binding>
8599
</pc:NumericUpDown.Value>
86100
</pc:NumericUpDown>
87101
<pc:NumericUpDown Width="200" Height="34"
102+
IsEnabled="False"
88103
Value="5"
89104
Maximum="10"
90105
ToolTip="ReadOnly"
91-
IsEnabled="False" IsReadOnly="True" />
106+
IsReadOnly="True" />
92107
</WrapPanel>
93108

94109
<TextBlock Text="TextPath:"
@@ -114,6 +129,19 @@
114129
pc:TextPath.DrawingRec="0,0,5,5" Stroke="Purple" StrokeThickness="2"
115130
Style="{StaticResource FillIconTextPathStyle}" />
116131
</WrapPanel>
132+
133+
<TextBlock Text="AutoGroupingText:"
134+
FontSize="20" FontWeight="DemiBold"
135+
Margin="0,30,0,10" />
136+
<WrapPanel>
137+
<StackPanel Height="200" Orientation="Horizontal">
138+
<pc:AutoGroupingText Text="{Binding AutoText}"
139+
FontSize="16" FontWeight="Bold"
140+
HeaderWidth="100" ItemHeight="50" SplitSymbol="&amp;" />
141+
<Button Content="Add Text" Margin="20,0" Click="Button_Click" />
142+
</StackPanel>
143+
</WrapPanel>
144+
117145
</StackPanel>
118146
</ScrollViewer>
119147

MvvmTestDemo/DemoViews/FieldsDemo.xaml.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Prism.Commands;
1+
using CookPopularControl.Controls;
2+
using CookPopularCSharpToolkit.Communal;
3+
using Prism.Commands;
24
using PropertyChanged;
35
using System;
46
using System.Windows;
@@ -18,6 +20,8 @@ public partial class FieldsDemo : UserControl
1820

1921
public double NumericValue { get; set; }
2022

23+
public string AutoText { get; set; } = "Cook:写代码的厨子&";
24+
2125
public DelegateCommand<object> Sure123Command => new Lazy<DelegateCommand<object>>(() => new DelegateCommand<object>(OnSure123)).Value;
2226

2327
private void OnSure123(object obj)
@@ -34,5 +38,13 @@ private void NumericUpDown_ValueChanged(object sender, RoutedPropertyChangedEven
3438
{
3539
var s = num5.Value;
3640
}
41+
42+
private int index = 1;
43+
private void Button_Click(object sender, RoutedEventArgs e)
44+
{
45+
AutoText += $"Title{index}:Chance{index}&";
46+
index++;
47+
//AutoText = "Title1:写代码的厨子 Title2:Chance Title3:Cook";
48+
}
3749
}
3850
}

MvvmTestDemo/DemoViews/GroupBoxDemo.xaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@
1010
d:DesignHeight="450"
1111
d:DesignWidth="1000">
1212

13-
<ScrollViewer>
13+
<ScrollViewer Padding="10,0">
1414
<WrapPanel HorizontalAlignment="Center" VerticalAlignment="Center">
15+
<GroupBox Width="300" Height="400"
16+
Header="写代码的厨子"
17+
Foreground="{StaticResource AssistantThemeBrush}"
18+
pc:GroupBoxAssistant.HeaderBackground="#F0F0F0"
19+
pc:GroupBoxAssistant.HeaderHorizontalAlignment="Left">
20+
<Border Background="Green">
21+
<Button Width="200" Height="40" Content="DefaultGroupBox" />
22+
</Border>
23+
</GroupBox>
1524
<GroupBox Width="300" Height="400"
1625
BorderBrush="Red" BorderThickness="4"
1726
Foreground="{StaticResource AssistantThemeBrush}"
1827
FontSize="20"
28+
Margin="30,0"
1929
pc:GroupBoxAssistant.HeaderBackground="#F0F0F0"
2030
pc:GroupBoxAssistant.HeaderHorizontalAlignment="Left">
2131
<GroupBox.Header>
@@ -27,14 +37,13 @@
2737
</GroupBox>
2838
<GroupBox Width="300" Height="400"
2939
Header="写代码的厨子"
30-
Margin="30,0"
3140
Style="{DynamicResource CustomHeaderGroupBoxStyle}">
3241
<Button Width="250" Height="40" Content="CustomHeaderGroupBox" />
3342
</GroupBox>
3443
<GroupBox Width="300" Height="400"
3544
Header="写代码的厨子"
3645
Foreground="#FFFFFF"
37-
Margin="0,0"
46+
Margin="30,0"
3847
pc:FrameworkElementBaseAttached.CornerRadius="0"
3948
pc:FrameworkElementBaseAttached.IconGeometry="{StaticResource EyeGeometry}"
4049
pc:FrameworkElementBaseAttached.ShadowEffect="{StaticResource ShadowEffectDepth3}"

0 commit comments

Comments
 (0)