Skip to content

Commit 9014ad6

Browse files
committed
1
1 parent 33d7a22 commit 9014ad6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3588
-106
lines changed

ControlTest/ControlTest.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
<Generator>MSBuild:Compile</Generator>
8080
<SubType>Designer</SubType>
8181
</ApplicationDefinition>
82+
<Compile Include="UserControl1.xaml.cs">
83+
<DependentUpon>UserControl1.xaml</DependentUpon>
84+
</Compile>
8285
<Page Include="MainWindow.xaml">
8386
<Generator>MSBuild:Compile</Generator>
8487
<SubType>Designer</SubType>
@@ -91,6 +94,10 @@
9194
<DependentUpon>MainWindow.xaml</DependentUpon>
9295
<SubType>Code</SubType>
9396
</Compile>
97+
<Page Include="UserControl1.xaml">
98+
<SubType>Designer</SubType>
99+
<Generator>MSBuild:Compile</Generator>
100+
</Page>
94101
</ItemGroup>
95102
<ItemGroup>
96103
<Compile Include="Properties\AssemblyInfo.cs">

ControlTest/MainWindow.xaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
</Window.Resources>
2626
<MyCustomControl:DrawerHost Background="White">
2727
<UniformGrid Rows="1">
28-
<MyCustomControl:JSpinner Name="bbb" CanEdit="True" SpinnerType="Range" Maximum="100" Minimum="10" Suffix="dB"></MyCustomControl:JSpinner>
29-
<ComboBox Name="ttt"></ComboBox>
28+
<MyCustomControl:JColorPicker></MyCustomControl:JColorPicker>
29+
<TextBlock Text="{Binding ElementName=bbb,Path=Text}"></TextBlock>
30+
<MyCustomControl:JSpinner Name="bbb" CanEdit="True" SpinnerType="ItemSource"></MyCustomControl:JSpinner>
31+
<MyCustomControl:JSlider IsUIFireEventDirectly="True" Orientation="Vertical" HorizontalAlignment="Center" Maximum="100" Name="ttt"></MyCustomControl:JSlider>
32+
<MyCustomControl:JSwitcher GroupName="aaa"></MyCustomControl:JSwitcher>
33+
<MyCustomControl:JSwitcher GroupName="aaa"></MyCustomControl:JSwitcher>
3034
</UniformGrid>
3135
</MyCustomControl:DrawerHost>
3236

ControlTest/MainWindow.xaml.cs

Lines changed: 114 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Linq;
5+
using System.Runtime.Serialization;
6+
using System.Security.Permissions;
57
using System.Text;
68
using System.Threading.Tasks;
79
using System.Windows;
@@ -14,6 +16,7 @@
1416
using System.Windows.Navigation;
1517
using System.Windows.Shapes;
1618
using JayCustomControlLib;
19+
using JayLib.JaySerialization;
1720
using JayLib.WPF.BasicClass;
1821

1922
namespace ControlTest
@@ -23,6 +26,11 @@ namespace ControlTest
2326
/// </summary>
2427
public partial class MainWindow : Window
2528
{
29+
public override void BeginInit()
30+
{
31+
base.BeginInit();
32+
}
33+
2634
public static string[] FaderTickStrings { get; private set; } = new string[]
2735
{
2836
"OFF", //0
@@ -51,15 +59,16 @@ public partial class MainWindow : Window
5159
public MainWindow()
5260
{
5361
InitializeComponent();
54-
bbb.CalculateValueFunction = dddd;
55-
//List<int> aa = new List<int>();
56-
//for (int i = 0; i < 10; i++)
57-
//{
58-
// aa.Add(i);
59-
//}
62+
colorPickerTest colorPickerTest = new colorPickerTest();
63+
//bbb.CalculateValueFunction = dddd;
64+
List<int> aa = new List<int>();
65+
for (int i = 0; i < 10; i++)
66+
{
67+
aa.Add(i);
68+
}
6069
//timer.Elapsed += Timer_Elapsed;
6170
//timer.Start();
62-
//bbb.ItemsSource = aa;
71+
bbb.ItemsSource = aa;
6372
//ttt.ItemsSource = aa;
6473
//bbb.SetBinding(JSpinner.ValueProperty, new Binding("Value") { Source = c ,Mode= BindingMode.OneWay});
6574
//ttt.SetBinding(ComboBox.SelectedIndexProperty, new Binding("Value") { Source = c ,Mode= BindingMode.OneWay});
@@ -93,6 +102,30 @@ public MainWindow()
93102
"10:1",
94103
"Limit"
95104
};
105+
106+
cac cccc = new cac()
107+
{
108+
Text = "ac",
109+
Value = 5,
110+
MyProperty = 1.1456,
111+
listint=new List<int>() { 1,2,3},
112+
listccc=new List<ccc>()
113+
{
114+
new ccc(){Text="a"},
115+
new ccc(){Text="b"}
116+
}
117+
};
118+
ccc aaa = new ccc()
119+
{
120+
Text = "aaa",
121+
Value = 6,
122+
};
123+
JSerializer.Serialize(cccc, AppDomain.CurrentDomain.BaseDirectory + "c.bin");
124+
JSerializer.Serialize(aaa, AppDomain.CurrentDomain.BaseDirectory + "a.bin");
125+
126+
var dccc = JSerializer.Deserialize(AppDomain.CurrentDomain.BaseDirectory + "c.bin") as cac;
127+
var accc = JSerializer.Deserialize(AppDomain.CurrentDomain.BaseDirectory + "a.bin") as ccc;
128+
int b = 0;
96129
}
97130
int i = 0;
98131
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
@@ -115,7 +148,29 @@ private int dddd(string b)
115148
}
116149
}
117150

118-
public class ccc : NotificationObject
151+
public class colorPickerTest:NotificationObject
152+
{
153+
private Brush mycolor;
154+
155+
public Brush myColor
156+
{
157+
get { return mycolor; }
158+
set { mycolor = value; OnPropertyChanged(() => myColor); }
159+
}
160+
161+
162+
private Brush mycolor2;
163+
164+
public Brush myColor2
165+
{
166+
get { return mycolor2; }
167+
set { mycolor2 = value; OnPropertyChanged(() => myColor2); }
168+
}
169+
170+
}
171+
172+
[Serializable]
173+
public class ccc : NotificationObject,ISerializable
119174
{
120175
private int _value;
121176

@@ -132,5 +187,56 @@ public string Text
132187
get { return _text; }
133188
set { _text = value; OnPropertyChanged(() => Text); }
134189
}
190+
191+
public List<int> listint { get; set; }
192+
public RelayCommand RelayCommand1 { get; set; }
193+
public RelayCommand<int> RelayCommand2 { get; set; }
194+
195+
private string testbool;
196+
197+
public ccc()
198+
{
199+
RelayCommand1 = new RelayCommand(RelayCommand1E);
200+
RelayCommand2 = new RelayCommand<int>(RelayCommand2E);
201+
testbool = "aaaa";
202+
}
203+
204+
private void RelayCommand2E(int obj)
205+
{
206+
207+
}
208+
209+
private void RelayCommand1E()
210+
{
211+
212+
}
213+
214+
public void GetObjectData(SerializationInfo info, StreamingContext context)
215+
{
216+
SerializerHelper.SerializationFieldHelper(info, this);
217+
SerializerHelper.SerializationPropertyHelper(info, this,typeof(int),typeof(RelayCommand),typeof(RelayCommand<int>));
218+
}
219+
220+
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
221+
protected ccc(SerializationInfo info, StreamingContext context)
222+
{
223+
SerializerHelper.DeserializtionPropertyHelper(info, this, typeof(int), typeof(RelayCommand), typeof(RelayCommand<int>));
224+
SerializerHelper.DeSerializationFieldHelper(info, this);
225+
}
226+
}
227+
[Serializable]
228+
public class cac:ccc
229+
{
230+
public double MyProperty { get; set; }
231+
public List<ccc> listccc { get; set; }
232+
public cac()
233+
{
234+
235+
}
236+
protected cac(SerializationInfo info, StreamingContext context)
237+
{
238+
SerializerHelper.DeserializtionPropertyHelper(info, this, typeof(int), typeof(RelayCommand), typeof(RelayCommand<int>));
239+
SerializerHelper.DeSerializationFieldHelper(info, this);
240+
}
135241
}
136242
}

ControlTest/UserControl1.xaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<UserControl x:Class="ControlTest.UserControl1"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:ControlTest"
7+
mc:Ignorable="d"
8+
d:DesignHeight="450" d:DesignWidth="800">
9+
<Grid>
10+
<ComboBox Name="aaa">
11+
</ComboBox>
12+
</Grid>
13+
</UserControl>

ControlTest/UserControl1.xaml.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Windows.Controls;
8+
using System.Windows.Data;
9+
using System.Windows.Documents;
10+
using System.Windows.Input;
11+
using System.Windows.Media;
12+
using System.Windows.Media.Imaging;
13+
using System.Windows.Navigation;
14+
using System.Windows.Shapes;
15+
16+
namespace ControlTest
17+
{
18+
/// <summary>
19+
/// UserControl1.xaml 的互動邏輯
20+
/// </summary>
21+
public partial class UserControl1 : UserControl
22+
{
23+
public UserControl1()
24+
{
25+
InitializeComponent();
26+
aaa.ItemsSource = new List<Brush> { Brushes.Red, Brushes.Green, Brushes.Blue };
27+
28+
aaa.SelectionChanged += Aaa_SelectionChanged;
29+
}
30+
31+
private void Aaa_SelectionChanged(object sender, SelectionChangedEventArgs e)
32+
{
33+
MyColor = (Brush)aaa.SelectedItem;
34+
}
35+
36+
public Brush MyColor
37+
{
38+
get { return (Brush)GetValue(MyColorProperty); }
39+
set { SetValue(MyColorProperty, value); }
40+
}
41+
42+
// Using a DependencyProperty as the backing store for MyColor. This enables animation, styling, binding, etc...
43+
public static readonly DependencyProperty MyColorProperty =
44+
DependencyProperty.Register("MyColor", typeof(Brush), typeof(UserControl1), new PropertyMetadata(Brushes.Red));
45+
46+
47+
}
48+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using JayCustomControlLib.CommonBasicClass;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Data;
10+
using System.Windows.Documents;
11+
using System.Windows.Input;
12+
using System.Windows.Media;
13+
using System.Windows.Media.Imaging;
14+
using System.Windows.Navigation;
15+
using System.Windows.Shapes;
16+
17+
namespace JayCustomControlLib
18+
{
19+
/// <summary>
20+
/// 依照步驟 1a 或 1b 執行,然後執行步驟 2,以便在 XAML 檔中使用此自訂控制項。
21+
///
22+
/// 步驟 1a) 於存在目前專案的 XAML 檔中使用此自訂控制項。
23+
/// 加入此 XmlNamespace 屬性至標記檔案的根項目為
24+
/// 要使用的:
25+
///
26+
/// xmlns:MyNamespace="clr-namespace:JayCustomControlLib"
27+
///
28+
///
29+
/// 步驟 1b) 於存在其他專案的 XAML 檔中使用此自訂控制項。
30+
/// 加入此 XmlNamespace 屬性至標記檔案的根項目為
31+
/// 要使用的:
32+
///
33+
/// xmlns:MyNamespace="clr-namespace:JayCustomControlLib;assembly=JayCustomControlLib"
34+
///
35+
/// 您還必須將 XAML 檔所在專案的專案參考加入
36+
/// 此專案並重建,以免發生編譯錯誤:
37+
///
38+
/// 在 [方案總管] 中以滑鼠右鍵按一下目標專案,並按一下
39+
/// [加入參考]->[專案]->[瀏覽並選取此專案]
40+
///
41+
///
42+
/// 步驟 2)
43+
/// 開始使用 XAML 檔案中的控制項。
44+
///
45+
/// <MyNamespace:JColorPicker/>
46+
///
47+
/// </summary>
48+
public class JColorPicker : Control
49+
{
50+
static JColorPicker()
51+
{
52+
DefaultStyleKeyProperty.OverrideMetadata(typeof(JColorPicker), new FrameworkPropertyMetadata(typeof(JColorPicker)));
53+
InitializeCommands();
54+
}
55+
56+
#region Commands
57+
58+
public static RoutedUICommand SelectColorCommand { get; private set; } = null;
59+
public static RoutedUICommand SelectAdvancedColorCommand { get; private set; } = null;
60+
private static void InitializeCommands()
61+
{
62+
//create instance
63+
SelectColorCommand = new RoutedUICommand("SelectColorCommand", "SelectColorCommand", typeof(JColorPicker));
64+
SelectAdvancedColorCommand = new RoutedUICommand("SelectAdvancedColorCommand", "SelectAdvancedColorCommand", typeof(JColorPicker));
65+
//register the command bindings, if the button gets clicked, the method will be called.
66+
CommandManager.RegisterClassCommandBinding(typeof(JColorPicker), new CommandBinding(SelectColorCommand, SelectedColorExecute));
67+
CommandManager.RegisterClassCommandBinding(typeof(JColorPicker), new CommandBinding(SelectAdvancedColorCommand, SelectedAdvancedColorExecute));
68+
// lastly bind some inputs: i.e. if the user presses up/down arrow
69+
// keys, call the appropriate commands.
70+
//MyCommandHelper.RegisterCommandHandler(typeof(JColorPicker), SelectColorCommand, SelectedColorExecute);
71+
//MyCommandHelper.RegisterCommandHandler(typeof(JColorPicker), SelectAdvancedColorCommand, SelectedAdvancedColorExecute);
72+
}
73+
74+
private static void SelectedColorExecute(object sender, ExecutedRoutedEventArgs e)
75+
{
76+
if (sender is JColorPicker jColorPicker && e.Parameter is string color)
77+
{
78+
jColorPicker.CurrentColor = new SolidColorBrush((Color)ColorConverter.ConvertFromString(color));
79+
}
80+
}
81+
82+
private static void SelectedAdvancedColorExecute(object sender, ExecutedRoutedEventArgs e)
83+
{
84+
85+
}
86+
87+
88+
#endregion
89+
90+
91+
public Brush CurrentColor
92+
{
93+
get { return (Brush)GetValue(CurrentColorProperty); }
94+
set { SetValue(CurrentColorProperty, value); }
95+
}
96+
97+
// Using a DependencyProperty as the backing store for CurrentColor. This enables animation, styling, binding, etc...
98+
public static readonly DependencyProperty CurrentColorProperty =
99+
DependencyProperty.Register("CurrentColor", typeof(Brush), typeof(JColorPicker), new PropertyMetadata(Brushes.Black));
100+
101+
}
102+
}

JayCustomControlLib/JLimitGDSlider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Collections.ObjectModel;
5+
using System.Globalization;
56
using System.Linq;
67
using System.Text;
78
using System.Text.RegularExpressions;
@@ -497,7 +498,7 @@ private bool CalculateRatio(string[] ratioStrings, out double res)
497498
res = 0;
498499
if (ratioStrings.Length == 2)
499500
{
500-
if (double.TryParse(ratioStrings[0], out double dividend) && double.TryParse(ratioStrings[1], out double divisor))
501+
if (double.TryParse(ratioStrings[0], System.Globalization.NumberStyles.Float,CultureInfo.InvariantCulture, out double dividend) && double.TryParse(ratioStrings[1], System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture, out double divisor))
501502
{
502503
res = dividend / divisor;
503504
return true;

0 commit comments

Comments
 (0)