【问题标题】:Windows IoT Raspberry Pi 3 C# Save Device SettingWindows IoT Raspberry Pi 3 C# 保存设备设置
【发布时间】:2017-10-26 08:35:59
【问题描述】:

我想知道如何为我选择的 USB 设备保存我的用户配置。每当我重新启动设备时,它将按照我之前选择的方式加载。 是保存在本地还是usb存储?

此应用说明Store and retrieve settings and other app data 是否适用于提到的应用数据类型适用于 USB 适配器?

更新:

当我从列表框中选择 USB 适配器时,我相应地设置了相应的选定设备。

        private void audioCaptureList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            recordPlayer.AudioDevice = captureDeviceList[audioCaptureList.SelectedIndex];
        }

        private void audioRenderList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            mediaPlayer.AudioDevice = renderDeviceList[audioRenderList.SelectedIndex];

        }

【问题讨论】:

    标签: c# save raspberry-pi3 windows-iot-core-10 user-config


    【解决方案1】:

    您的设置可以保存为Local app data。即使您重新启动设备,这些数据也不会改变。但是注意:the lifetime of the app data is tied to the lifetime of the app. If the app is removed, all of the app data will be lost as a consequence

    您可以像这样存储和检索本地应用数据:

        Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
    
        private void StoreButton_Click(object sender, RoutedEventArgs e)
        {
            var selection = ConnectDevices.SelectedItems;
            var entry = (DeviceListEntry)selection[0];
            var device = entry.DeviceInformation;
    
            localSettings.Values["SelectedUsbDeviceId"] =  device.Id;
            localSettings.Values["SelectedUsbDeviceName"] = device.Name;
        }
    
        private void RetrieveButton_Click(object sender, RoutedEventArgs e)
        {
            Object deviceId = localSettings.Values["SelectedUsbDeviceId"];
            Object deviceName = localSettings.Values["SelectedUsbDeviceName"];
        }
    

    【讨论】:

    • 嗨丽塔,我可以知道 devicelistentry 指的是什么吗?据我所知,“ConnectDevices”在我的案例“audioRenderList”中指的是ListBox。如果我错了,请纠正我。我还更新了我的 selectionchanged 代码。谢谢。
    • 嗨丽塔,在我声明“Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;”之后它触发了异常处理程序。还有什么需要我照顾的吗?
    • @mylim 你可以找到 devicelistentry here。有什么例外?
    猜你喜欢
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-21
    • 2019-07-04
    相关资源
    最近更新 更多