【问题标题】:windows store app settingwindows 商店应用设置
【发布时间】:2014-02-03 07:19:08
【问题描述】:
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 小时模式并关闭应用程序,则它设置为永久,切换开关是 12 小时模式设置永久)请帮助或任何示例应用程序,以了解如何应用程序设置工作我不需要 Windows sdk 示例它唯一的显示如何添加设置,我想如何使用该设置 *

【问题讨论】:

  • SDK 示例中有哪些不清楚的地方以及到目前为止您尝试了哪些?
  • 是的,但 sdk 示例仅显示如何添加设置页面,我想使用该设置添加设置工作

标签: c# windows windows-store-apps


【解决方案1】:

为此,您需要将值保存在ApplicationData.LocalSettings

然后,当您加载应用程序时,您需要根据存储的设置填充这些字段。我建议创建一个 SettingsViewModel 来完成此操作。它既可以初始化自身(并从设置对象中读取数据),也可以为您的弹出窗口提供绑定访问器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 2016-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多