如何使用设置存储在uwp中保存颜色?

问题描述 投票:0回答:1


我想使用设置存储在UWP中保存边框颜色。

有任何想法吗?。

string colors uwp
1个回答
1
投票

将颜色存储为字符串:使用ToString类的Color方法将颜色转换为字符串,将ColorHelper.ToColor()转换回UWP Community Toolkit

    private void SaveColor(Color color)
    {
        Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
        localSettings.Values["color"] = color.ToString();
    }
    private Color LoadColor()
    {
        Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
        return Microsoft.Toolkit.Uwp.Helpers.ColorHelper.ToColor((string) localSettings.Values["color"]);
    }
© www.soinside.com 2019 - 2024. All rights reserved.