// Copyright (c) Microsoft Corporation
and Contributors.
// Licensed under the MIT License.
using Microsoft.UI.Xaml;
using Microsoft.VisualBasic;
using System;
using Windows.Storage;
namespace winapp_settings_model
{
/// <summary>
/// demo to show settings
/// </summary>
public sealed partial class MainWindow : Window
{
private const string UsersKey = "users";
private
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
ApplicationDataContainer _users_Settings_container = null;
public MainWindow()
{
this.InitializeComponent();
_users_Settings_container =
localSettings.CreateContainer(UsersKey,
ApplicationDataCreateDisposition.Always);
}
private void btnSaveSetting_Click(object sender, RoutedEventArgs
e)
{
//create data based on model class
UserData_Model userdata_01 = new UserData_Model()
{
ip = "127.0.0.1",
user = "raimund",
path = "D:"
};
//convert to named settings
ApplicationDataCompositeValue
userdata_setting =new
ApplicationDataCompositeValue();
userdata_setting["ip"] = userdata_01.ip;
userdata_setting["user"] = userdata_01.user;
userdata_setting["path"] = userdata_01.path;
//save setting
_users_Settings_container.Values["userdata_" + 1] =
userdata_setting;
ctlLog.Text = DateTime.Now + " saved " ;
}
private void btnLoadSetting_Click(object sender, RoutedEventArgs
e)
{
//ApplicationDataCompositeValue
userdata_setting = new ApplicationDataCompositeValue();
//save setting
ApplicationDataCompositeValue
userdata_setting = (ApplicationDataCompositeValue)
_users_Settings_container.Values["userdata_" + 1] ;
//create data based on model class
UserData_Model userdata_01 = new UserData_Model();
userdata_01.ip =
userdata_setting["ip"].ToString();
userdata_01.user =
userdata_setting["user"].ToString();
userdata_01.path =
userdata_setting["path"].ToString();
//output to log
ctlLog.Text = DateAndTime.Now + " " + "ip=" + userdata_01.ip + " user=" + userdata_01.user + " path= " + userdata_01.path +
Environment.NewLine + ctlLog.Text ;
}
public class UserData_Model
{
public string ip;
public string user;
public string path;
}
}
}
|