Przeglądaj źródła

1. WPF 属性表格研究,为了开发工具时不用手动写入多个属性控件
2. 所有基础数据新增 Category 特性
3. 依赖库更新

Shun 2 lat temu
rodzic
commit
09b0e5a1c3

+ 5 - 0
README.md

@@ -539,3 +539,8 @@ while(true)
 1. 自动更新工具新增自动打包,一键式完整发布流程
 2. 工具主界面修改,性能优化,更友好的交互
 3. 采集协议、传输协议工具开发,正在进行中
+
+#### 2023-12-14
+1. WPF 属性表格研究,为了开发工具时不用手动写入多个属性控件
+2. 所有基础数据新增 Category 特性
+3. 依赖库更新

+ 3 - 0
src/YSAI.Core.Wpf/YSAI.Core.Wpf.csproj

@@ -42,5 +42,8 @@
 	    <SubType>Code</SubType>
 	  </Compile>
 	</ItemGroup>
+	<ItemGroup>
+	  <Folder Include="controls\propertygrid\" />
+	</ItemGroup>
 
 </Project>

+ 2 - 2
src/YSAI.Tool.Wpf/YSAI.Tool.Wpf.csproj

@@ -14,8 +14,8 @@
     <Resource Include="image\YSAI_Two.ico" />
   </ItemGroup>
 	<ItemGroup>
-		<PackageReference Include="HandyControl" Version="3.4.0" />
-		<PackageReference Include="WPF-UI" Version="3.0.0-preview.12" />
+		<PackageReference Include="PropertyTools.Wpf" Version="3.1.0" />
+		<PackageReference Include="WPF-UI" Version="3.0.0-preview.13" />
 		<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2210.55" />
 		<PackageReference Include="YSAI.AllenBradley" Version="23.347.21444" />
 		<PackageReference Include="YSAI.Beckhoff" Version="23.347.21444" />

+ 1 - 1
src/YSAI.Tool.Wpf/controllers/MainController.cs

@@ -31,7 +31,7 @@ namespace YSAI.Tool.Wpf.controllers
                         Icon = new SymbolIcon { Symbol = SymbolRegular.Toolbox12 , Filled = true },
                         MenuItems = new object[]
                         {
-                            CreationControl(string.Format("{0,-8}{1}", "[ 客户端 ]", "UA"), SymbolRegular.DocumentTextToolbox24, typeof(AboutUs)).NavigationCacheMode=NavigationCacheMode.Required,
+                            CreationControl(string.Format("{0,-8}{1}", "[ 客户端 ]", "UA"), SymbolRegular.DocumentTextToolbox24, typeof(AboutUs)),
                             CreationControl(string.Format("{0,-8}{1}", "[ 服务端 ]", "UA"), SymbolRegular.DesktopToolbox24, typeof(AboutUs)),
                             CreationControl(string.Format("{0,-8}{1}", "[ 客户端 ]", "DA"), SymbolRegular.ClockToolbox24, null),
                             CreationControl(string.Format("{0,-8}{1}", "[ HTTP ]", "DA"), SymbolRegular.BookToolbox24, typeof(AboutUs))

+ 85 - 0
src/YSAI.Tool.Wpf/test.xaml

@@ -0,0 +1,85 @@
+<UserControl x:Class="YSAI.Tool.Wpf.test"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:c="clr-namespace:YSAI.Tool.Wpf"
+             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
+             xmlns:mvvm="clr-namespace:YSAI.Core.Wpf.mvvm;assembly=YSAI.Core.Wpf"
+             xmlns:pt="http://propertytools.org/wpf"
+             xmlns:helpers="clr-namespace:YSAI.Core.Wpf.style;assembly=YSAI.Core.Wpf"
+             xmlns:btn="clr-namespace:YSAI.Core.Wpf.controls.button;assembly=YSAI.Core.Wpf" Width="700" Height="700">
+    <!--加载控制器-->
+    <UserControl.DataContext>
+        <c:testC />
+    </UserControl.DataContext>
+
+    <Grid  Background="White">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="auto"/>
+            <RowDefinition Height="auto"/>
+        </Grid.RowDefinitions>
+        <!--属性表格-->
+        <Grid>
+            <Grid.Resources>
+                <ResourceDictionary>
+                    <ResourceDictionary.MergedDictionaries>
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_ComboBox.xaml" />
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_Button.xaml" />
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_DataGrid.xaml" />
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_Border.xaml" />
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_TbaControl.xaml" />
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_ScrollViewer.xaml" />
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_GroupBox.xaml" />
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_TextBox.xaml" />
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_TreeDataGrid.xaml" />
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_CheckBox.xaml" />
+                        <ResourceDictionary Source="pack://application:,,,/YSAI.Core.Wpf;component/resources/style/Style_RadioButton.xaml" />
+                    </ResourceDictionary.MergedDictionaries>
+                    <Style TargetType="{x:Type Label}" >
+                        <Setter Property="Foreground" Value="{DynamicResource Font.Content.Foreground}"/>
+                        <Setter Property="HorizontalAlignment" Value="Left"/>
+                    </Style>
+                    <Style TargetType="ToolTip">
+                        <Setter Property="Foreground" Value="{DynamicResource Font.Content.Foreground}"/>
+                        <Setter Property="BorderBrush" Value="{DynamicResource Control.Border.Color}"/>
+                    </Style>
+                    <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource DefaultComboBox}" >
+                        <Setter Property="Height" Value="25"/>
+                        <Setter Property="Background" Value="White"/>
+                        <Setter Property="VerticalAlignment" Value="Center"/>
+                        <Setter Property="helpers:Style_ComboBox.CornerRadius" Value="{DynamicResource WindowCornerRadius}"/>
+                    </Style>
+                    <Style TargetType="{x:Type pt:TextBoxEx}" BasedOn="{StaticResource TextBoxStyle2}">
+                        <Setter Property="Height" Value="25"/>
+                        <Setter Property="Foreground" Value="{DynamicResource Font.Content.Foreground}"/>
+                        <Setter Property="BorderBrush" Value="{DynamicResource Control.Border.Color}"/>
+                        <Setter Property="HorizontalContentAlignment" Value="Center"/>
+                        <Setter Property="VerticalContentAlignment" Value="Center"/>
+                    </Style>
+                    <Style TargetType="GroupBox" BasedOn="{StaticResource GroupBoxTab}"/>
+                    <Style TargetType="CheckBox" BasedOn="{StaticResource CheckBoxStyle}"/>
+                </ResourceDictionary>
+            </Grid.Resources>
+            <pt:PropertyGrid 
+                      SelectedObject="{Binding DataMode}"
+                      TabVisibility="VisibleIfMoreThanOne" 
+                      TextBlock.Foreground="{DynamicResource Font.Content.Foreground}" 
+                      Foreground="{DynamicResource Font.Content.Foreground}"
+                      BorderBrush="{DynamicResource Control.Border.Color}"
+                      CategoryControlType="GroupBox"/>
+        </Grid>
+
+        <btn:ButtonControl  Grid.Row="1"  Width="80"  Command="{Binding Start}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,10,0"
+                     IsMouseOverBorderBrushColor="{DynamicResource Control.Border.One.Color}"
+                     BorderBrush="{DynamicResource Control.Border.Color}"
+                     IsPressedBorderBrushColor="{DynamicResource Control.Border.Two.Color}"
+                     Foreground="{DynamicResource Font.Content.Foreground}"
+                     Icon="{DynamicResource Start}"
+                     Content="测试"
+                     CornerRadius="{DynamicResource WindowCornerRadius}" />
+    </Grid>
+    
+    
+   
+</UserControl>

+ 1 - 1
src/YSAI.Tool.Wpf/views/test.xaml.cs

@@ -1,6 +1,6 @@
 using System.Windows.Controls;
 
-namespace YSAI.Tool.Wpf.views
+namespace YSAI.Tool.Wpf
 {
     /// <summary>
     /// test.xaml 的交互逻辑

+ 156 - 0
src/YSAI.Tool.Wpf/testC.cs

@@ -0,0 +1,156 @@
+using System.ComponentModel;
+using System.Windows.Input;
+using YSAI.Core.Wpf.mvvm;
+using YSAI.Unility;
+
+namespace YSAI.Tool.Wpf
+{
+    public class Basics
+    {
+        //
+        // 摘要:
+        //     唯一标识符
+        [Category("基础数据")]
+        [Description("唯一标识符")]
+        public string? SN { get; set; } = Guid.NewGuid().ToUpperNString();
+
+
+        //
+        // 摘要:
+        //     用户名
+        [Description("用户名")]
+        public string? UserName { get; set; }
+
+        //
+        // 摘要:
+        //     密码
+        [Description("密码")]
+        public string? Password { get; set; }
+
+        //
+        // 摘要:
+        //     证书路径
+        [Description("证书路径")]
+        public string? Cer { get; set; }
+
+        //
+        // 摘要:
+        //     密钥
+        [Description("密钥")]
+        public string? SecreKey { get; set; }
+
+        //
+        // 摘要:
+        //     服务地址
+        [Description("服务地址")]
+        public string? ServerUrl { get; set; }
+
+        //
+        // 摘要:
+        //     客户端名称(唯一)
+        [Description("客户端名称")]
+        public string? CustomName { get; set; } = Guid.NewGuid().ToLowerNString();
+
+
+        //
+        // 摘要:
+        //     超时时间
+        [Description("超时时间")]
+        public int Timeout { get; set; } = 5000;
+
+
+        //
+        // 摘要:
+        //     是否需要断开重新连接
+        [Description("是否需要断开重新连接")]
+        public bool InterruptReconnection { get; set; } = true;
+
+
+        //
+        // 摘要:
+        //     重连间隔(毫秒)
+        [Description("重连间隔")]
+        public int ReconnectionInterval { get; set; } = 2000;
+
+
+        //
+        // 摘要:
+        //     取样时间间隔
+        [Description("取样时间间隔")]
+        public int SamplingInterval { get; set; } = 100;
+
+
+        //
+        // 摘要:
+        //     发布时间间隔
+        [Description("发布时间间隔")]
+        public int PublishingInterval { get; set; } = 1000;
+
+
+        //
+        // 摘要:
+        //     保活计数, 如果到发布周期但没有新数据,服务端会跳过但保活次数定义了最多可以跳过多少次,之后哪怕是空消息也要发给客户端,告诉客户的订阅仍然有效,但没数据
+        [Description("保活计数")]
+        public int KeepAliveCount { get; set; } = 261120;
+
+
+        //
+        // 摘要:
+        //     寿命计数, 客户端有责任向服务端发送订阅请求,然后服务端才能发送数据变更通知。服务端通过判断是否有新的请求来判断客户端是否活着。LifeTimeCount定义新请求之前最多允许多少个发布周期,超过后服务端判定客户端失活,清除订阅,
+        //     必须是【保活计数】的三倍以“上”
+        [Description("寿命计数")]
+        public int LifetimeCount { get; set; } = 783360;
+
+
+        //
+        // 摘要:
+        //     队列大小
+        [Description("队列大小")]
+        public int QueueSize { get; set; } = 1020;
+
+
+        //
+        // 摘要:
+        //     订阅单组最大数, 0:不执行分组,数据少时使用, 100:每组订阅100个数据点,自动根据传入的值分组,你有1000个点位,每组最大数是100,这时就会自动分配10个组来执行订阅
+        //     数据是根据实际情况来定
+        [Description("订阅单组最大数")]
+        public int SubscribeSingleGroupMaxCount { get; set; }
+
+        //
+        // 摘要:
+        //     任务数量
+        [Description("任务数量")]
+        public int TaskNumber { get; set; } = 5;
+
+
+        //
+        // 摘要:
+        //     任务处理间隔(毫秒)
+        [Description("任务处理间隔")]
+        public int TaskHandleInterval { get; set; } = 100;
+
+    }
+    public class testC : NotifyObject
+    {
+        public testC()
+        {
+            DataMode = new Basics();
+        }
+        /// <summary>
+        /// 数据源
+        /// </summary>
+        public Basics DataMode
+        {
+            get => GetProperty(() => DataMode);
+            set => SetProperty(() => DataMode, value);
+        }
+
+        public ICommand Start { get => new CommandX(OnStart); }
+
+        public void OnStart()
+        {
+
+            Console.WriteLine();
+        }
+    }
+}

+ 0 - 34
src/YSAI.Tool.Wpf/views/test.xaml

@@ -1,34 +0,0 @@
-<UserControl x:Class="YSAI.Tool.Wpf.views.test"
-             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-             xmlns:c="clr-namespace:YSAI.Tool.Wpf.views"
-             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
-             xmlns:mvvm="clr-namespace:YSAI.Core.Wpf.mvvm;assembly=YSAI.Core.Wpf"
-             xmlns:hc="https://handyorg.github.io/handycontrol" >
-    <!--加载控制器-->
-    <UserControl.DataContext>
-        <c:testC />
-    </UserControl.DataContext>
-    <Grid>
-        <Grid.Resources>
-            <ResourceDictionary>
-                <ResourceDictionary.MergedDictionaries>
-                    <ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
-                    <ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
-
-                </ResourceDictionary.MergedDictionaries>
-            </ResourceDictionary>
-        </Grid.Resources>
-        <hc:TransitioningContentControl>
-            <hc:PropertyGrid Width="500" SelectedObject="{Binding DataMode}" ShowSortButton="True" Description="{Binding ms}">
-                <i:Interaction.Triggers>
-                    <i:EventTrigger EventName="SelectedObjectChanged">
-                        <mvvm:EventCommand  Command="{Binding PropertyGrid_SelectedObjectChanged}" />
-                    </i:EventTrigger>
-                </i:Interaction.Triggers>
-            </hc:PropertyGrid>
-        </hc:TransitioningContentControl>
-    </Grid>
-</UserControl>

+ 0 - 40
src/YSAI.Tool.Wpf/views/testC.cs

@@ -1,40 +0,0 @@
-using System.Windows.Input;
-using YSAI.Core.Wpf.mvvm;
-using YSAI.Siemens;
-
-namespace YSAI.Tool.Wpf.views
-{
-    public class testC : NotifyObject
-    {
-        public testC()
-        {
-            DataMode = new SiemensData.Basics();
-
-        }
-        /// <summary>
-        /// 数据源
-        /// </summary>
-        public SiemensData.Basics DataMode
-        {
-            get => GetProperty(() => DataMode);
-            set => SetProperty(() => DataMode, value);
-        }
-
-        public string ms
-        {
-            get => GetProperty(() => ms);
-            set => SetProperty(() => ms, value);
-        }
-
-
-        /// <summary>
-        /// 信息框事件
-        /// </summary>
-        public ICommand PropertyGrid_SelectedObjectChanged { get => new CommandX<object>(OnPropertyGrid_SelectedObjectChanged); }
-        private void OnPropertyGrid_SelectedObjectChanged(object e)
-        {
-            ms = "666";
-            Console.WriteLine();
-        }
-    }
-}