public sealed partial class MainPage : Page
{
DispatcherTimer timer = new DispatcherTimer();
public MainPage()
{
this.InitializeComponent();
timer.Interval = TimeSpan.FromMilliseconds(1);
timer.Tick += timer_Tick;
timer.Start();
}
void timer_Tick(object sender, object e)
{
DateTime mytime = DateTime.Now;
string time12 = mytime.ToString("hh:mm:ss tt"); // time 12 hours
string Use24H = mytime.ToString("HH:mm:ss"); // time 24 hours
dititalclock.Text = time12;
}
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBlock x:Name="dititalclock" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Height="537" Width="1366" FontSize="300" FontFamily="Digital-7" Margin="0,231,0,0" Foreground="#FFE42525"/>
</Grid>
设置页面
public sealed partial class SettingsFlyout1 : SettingsFlyout
{
public SettingsFlyout1()
{
this.InitializeComponent();
}
<SettingsFlyout
x:Class="ClockTest.SettingsFlyout1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ClockTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
IconSource="Assets/SmallLogo.png"
Title="SettingsFlyout1"
d:DesignWidth="346">
<!-- This StackPanel acts as a root panel for vertical layout of the content sections -->
<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<!-- The StackPanel(s) below define individual content sections -->
<!-- Content Section 1-->
<StackPanel Style="{StaticResource SettingsFlyoutSectionStyle}">
<!-- Section 1 header -->
<!-- Section 1 body -->
</StackPanel>
<TextBlock TextWrapping="Wrap" Text="24 Hours" Height="28" FontSize="25"/>
<ToggleSwitch x:Name="utctime24" Header="ToggleSwitch" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="88" Width="187"/>
<!-- Define more Content Sections below as necessary -->
</StackPanel>
* 我想打开开关然后时间显示为24小时模式,然后12小时保存设置,如果我关闭应用程序再次开始发送我保存将导致运行应用程序(如果切换24小时模式切换并关闭应用程序设置永久,togle swich是12小时模式seeting永久)plase帮助或任何示例应用程序如何应用程序设置工作我不需要Windows sdk示例其唯一显示如何添加设置,我想如何使用该设置*
答案 0 :(得分:0)
要执行此操作,您需要将值保存在ApplicationData。LocalSettings。
然后,当您加载应用程序时,您需要根据存储的设置填充这些字段。我建议创建一个SettingsViewModel来完成此任务。它既可以初始化自己(也可以读取设置对象的数据),也可以为你的弹出窗口提供绑定访问器。