0

I would like to know how to save my user config for my selected USB devices. Whenever i restart the device it will load as i selected previously. is it advisable to save locally or in the usb storage?

Does this app note Store and retrieve settings and other app data applicable as types of app data mentioned works with USB adapter?

selected devices

Updated:

When I selected the USB adapter from the listbox, I set the respective selected device accordingly.

        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];

        }
mylim
  • 313
  • 4
  • 16

1 Answers1

0

Your setting can be saved as Local app data. These data will not change even you restart the device. But note: 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.

You can store and retrieve local app data like this:

    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"];
    }
Rita Han
  • 9,574
  • 1
  • 11
  • 24
  • Hi Rita, may i know what is devicelistentry referring to? as i can understand, "ConnectDevices" is referring to the ListBox in my case "audioRenderList". Please correct me if i am wrong. I have also updated my selectionchanged code. Thanks. – mylim Oct 28 '17 at 01:15
  • Hi Rita, after i declared 'Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;' it triggered exception handler. Is there anything else I need to take care of? – mylim Oct 28 '17 at 17:49
  • @mylim You can find devicelistentry [here](https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/CustomUsbDeviceAccess/cs/DeviceListEntry.cs). What's the exception? – Rita Han Oct 30 '17 at 07:27