diff --git a/doc/source/handycontrol/attach/iconSwitchElement/index.md b/doc/source/handycontrol/attach/iconSwitchElement/index.md index ca12ad62..adffe69d 100644 --- a/doc/source/handycontrol/attach/iconSwitchElement/index.md +++ b/doc/source/handycontrol/attach/iconSwitchElement/index.md @@ -1,5 +1,13 @@ --- -title: 建设中 +title: IconSwitchElement 可切换图标的元素 --- -建设中 \ No newline at end of file +{% note info no-icon %} +继承自 [IconElement](https://handyorg.github.io/handycontrol/attach/iconElement/) +{% endnote %} + +# 属性 + +| 名称 | 用途 | +|-|-| +| GeometrySelected | 选中时的几何形状 | \ No newline at end of file diff --git a/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj b/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj index 1b7528d8..01ca2c13 100644 --- a/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj +++ b/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj @@ -391,6 +391,9 @@ Resources\fabric-icons.ttf + + Resources\Registry.txt + Resources\Img\LeftMainContent\brackets_Square_16xLG.png diff --git a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj index 6ea01470..1df7079e 100644 --- a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj +++ b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj @@ -420,6 +420,9 @@ Resources\fabric-icons.ttf + + Resources\Registry.txt + diff --git a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj index d7566d1b..372bc73c 100644 --- a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj +++ b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj @@ -567,6 +567,9 @@ Resources\fabric-icons.ttf + + Resources\Registry.txt + diff --git a/src/Shared/HandyControlDemo_Shared/App.xaml.cs b/src/Shared/HandyControlDemo_Shared/App.xaml.cs index 1392706a..167cef26 100644 --- a/src/Shared/HandyControlDemo_Shared/App.xaml.cs +++ b/src/Shared/HandyControlDemo_Shared/App.xaml.cs @@ -1,6 +1,10 @@ using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.IO; using System.Net; using System.Security.Authentication; +using System.Threading; using System.Windows; using HandyControl.Data; using HandyControl.Tools; @@ -11,10 +15,36 @@ namespace HandyControlDemo { public partial class App { + // ReSharper disable once NotAccessedField.Local + [SuppressMessage("代码质量", "IDE0052:删除未读的私有成员", Justification = "<挂起>")] + private static Mutex AppMutex; + + public App() + { + AppMutex = new Mutex(true, "HandyControlDemo", out var createdNew); + + if (!createdNew) + { + var current = Process.GetCurrentProcess(); + + foreach (var process in Process.GetProcessesByName(current.ProcessName)) + { + if (process.Id != current.Id) + { + Win32Helper.SetForegroundWindow(process.MainWindowHandle); + break; + } + } + Shutdown(); + } + } + protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); + UpdateRegistry(); + ShutdownMode = ShutdownMode.OnMainWindowClose; GlobalData.Init(); ConfigHelper.Instance.SetLang(GlobalData.Config.Lang); @@ -54,5 +84,30 @@ namespace HandyControlDemo }); Current.MainWindow?.OnApplyTemplate(); } + + private void UpdateRegistry() + { + var processModule = Process.GetCurrentProcess().MainModule; + if (processModule != null) + { + var registryFilePath = $"{Path.GetDirectoryName(processModule.FileName)}\\Registry.reg"; + if (!File.Exists(registryFilePath)) + { + var streamResourceInfo = GetResourceStream(new Uri("pack://application:,,,/Resources/Registry.txt")); + if (streamResourceInfo != null) + { + using var reader = new StreamReader(streamResourceInfo.Stream); + var registryStr = reader.ReadToEnd(); + var newRegistryStr = registryStr.Replace("#", processModule.FileName.Replace("\\", "\\\\")); + File.WriteAllText(registryFilePath, newRegistryStr); + Process.Start(new ProcessStartInfo("cmd", $"/c {registryFilePath}") + { + UseShellExecute = false, + CreateNoWindow = true + }); + } + } + } + } } } diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems index 53ef32fc..6128b123 100644 --- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems +++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems @@ -33,6 +33,7 @@ + Avatar.xaml diff --git a/src/Shared/HandyControlDemo_Shared/Resources/Registry.txt b/src/Shared/HandyControlDemo_Shared/Resources/Registry.txt new file mode 100644 index 00000000..70b43050 Binary files /dev/null and b/src/Shared/HandyControlDemo_Shared/Resources/Registry.txt differ diff --git a/src/Shared/HandyControlDemo_Shared/Tools/Helper/Win32Helper.cs b/src/Shared/HandyControlDemo_Shared/Tools/Helper/Win32Helper.cs new file mode 100644 index 00000000..0f8aeb4b --- /dev/null +++ b/src/Shared/HandyControlDemo_Shared/Tools/Helper/Win32Helper.cs @@ -0,0 +1,11 @@ +using System; +using System.Runtime.InteropServices; + +namespace HandyControlDemo.Tools +{ + internal class Win32Helper + { + [DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)] + public static extern bool SetForegroundWindow(IntPtr hWnd); + } +}