新新设置的第一个开关设置选项 开机时启动
This commit is contained in:
@@ -4,14 +4,42 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Ink_Canvas.Windows.SettingsViews2.Pages"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
|
||||
xmlns:i18n="clr-namespace:Ink_Canvas.MarkupExtensions"
|
||||
xmlns:sys="clr-namespace:System;assembly=mscorlib"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
Title="启动">
|
||||
|
||||
<Grid>
|
||||
<StackPanel Margin="24">
|
||||
<TextBlock Text="启动设置" Style="{DynamicResource TitleTextBlockStyle}" Margin="0,0,0,16" />
|
||||
<TextBlock Text="这里是启动设置页面" Style="{DynamicResource BodyTextBlockStyle}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<ScrollViewer Padding="20,0">
|
||||
<!-- These styles can be referenced to create a consistent SettingsPage layout -->
|
||||
<FrameworkElement.Resources>
|
||||
<!-- Spacing between cards -->
|
||||
<sys:Double x:Key="SettingsCardSpacing">4</sys:Double>
|
||||
<!-- Style (inc. the correct spacing) of a section header -->
|
||||
<Style x:Key="SettingsSectionHeaderTextBlockStyle"
|
||||
BasedOn="{StaticResource BodyStrongTextBlockStyle}"
|
||||
TargetType="TextBlock">
|
||||
<Style.Setters>
|
||||
<Setter Property="Margin" Value="1,30,0,6" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
</FrameworkElement.Resources>
|
||||
<Grid>
|
||||
<ikw:SimpleStackPanel MaxWidth="1000"
|
||||
HorizontalAlignment="Stretch"
|
||||
Spacing="{StaticResource SettingsCardSpacing}">
|
||||
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"
|
||||
Text="启动设置" />
|
||||
<ui:SettingsCard Description="系统启动时自动运行软件"
|
||||
Header="开机时运行">
|
||||
<ui:SettingsCard.HeaderIcon>
|
||||
<ui:FontIcon Glyph="" />
|
||||
</ui:SettingsCard.HeaderIcon>
|
||||
<ui:ToggleSwitch Name="ToggleSwitchRunAtStartup" Toggled="ToggleSwitchRunAtStartup_Toggled" />
|
||||
</ui:SettingsCard>
|
||||
</ikw:SimpleStackPanel>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Page>
|
||||
@@ -23,6 +23,73 @@ namespace Ink_Canvas.Windows.SettingsViews2.Pages
|
||||
public NewSettingStartup()
|
||||
{
|
||||
InitializeComponent();
|
||||
// 初始化开关状态
|
||||
InitializeSwitchState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化开关状态
|
||||
/// </summary>
|
||||
private void InitializeSwitchState()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 通过检查启动文件夹中是否存在快捷方式来判断开机自启动状态
|
||||
if (System.IO.File.Exists(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup) + "\\Ink Canvas Annotation.lnk"))
|
||||
{
|
||||
ToggleSwitchRunAtStartup.IsOn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ToggleSwitchRunAtStartup.IsOn = false;
|
||||
}
|
||||
|
||||
// 同步主窗口的开关状态
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
if (mainWindow != null && mainWindow.ToggleSwitchRunAtStartup != null)
|
||||
{
|
||||
mainWindow.ToggleSwitchRunAtStartup.IsOn = ToggleSwitchRunAtStartup.IsOn;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 如果发生异常,默认设置为关闭
|
||||
ToggleSwitchRunAtStartup.IsOn = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理开机自启动开关状态更改事件
|
||||
/// </summary>
|
||||
/// <param name="sender">事件发送者</param>
|
||||
/// <param name="e">路由事件参数</param>
|
||||
private void ToggleSwitchRunAtStartup_Toggled(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 直接实现开机自启动逻辑
|
||||
if (ToggleSwitchRunAtStartup.IsOn)
|
||||
{
|
||||
MainWindow.StartAutomaticallyDel("InkCanvas");
|
||||
MainWindow.StartAutomaticallyCreate("Ink Canvas Annotation");
|
||||
}
|
||||
else
|
||||
{
|
||||
MainWindow.StartAutomaticallyDel("InkCanvas");
|
||||
MainWindow.StartAutomaticallyDel("Ink Canvas Annotation");
|
||||
}
|
||||
|
||||
// 同步到主窗口的设置
|
||||
var mainWindow = Application.Current.MainWindow as MainWindow;
|
||||
if (mainWindow != null && mainWindow.ToggleSwitchRunAtStartup != null)
|
||||
{
|
||||
mainWindow.ToggleSwitchRunAtStartup.IsOn = ToggleSwitchRunAtStartup.IsOn;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// 忽略异常
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user