I'm developing the Windows 8 equivalent of my app.
I'm trying to save simple list of strings to ApplicationDataContainer, as I would with IsolatedStorage for Windows Phone 8.
In Windows Phone 8 I would do it like this:
List<String> myList;
myList= readSetting("myList") != null ? (List<String>)readSetting("myList") : new List<String>();
Helper method:
private static object readSetting(string key)
{
return IsolatedStorageSettings.ApplicationSettings.Contains(key) ? IsolatedStorageSettings.ApplicationSettings[key] : null;
}
But how should I do this in Windows 8? My app is of the type Split Page.
Thanks a lot!
Kind Regards,
Erik
Try using Storage Helpers like this and this. Or you can use StorageFile in Windows 8 which allows you read-write files in local folder
The equivalent to IsolatedStorageSettings on Win8 (and WP8) is ApplicationData.Current.LocalSettings
Create a container
var container = ApplicationData.Current.LocalSettings.CreateContainer("defaultContainer",ApplicationDataCreateDisposition.Always);
container.Values["newKey"] = "New Value";
Your method would become:
private static object readSetting(string key)
{
var container = ApplicationData.Current.LocalSettings.CreateContainer("defaultContainer",ApplicationDataCreateDisposition.Existing);
if (container == null)
{
return null;
}
return Container.Values[key]
}
Note that this will also work on Windows Phone 8 if you would like to reuse some code between the two platforms.
Related
Good day,
in android phone -> virtual keyboard, system list all the enabled keyboards in this page, how can i get all enabled keyboards type with C# in my Xamarin.forms APP?
Thanks!
Roll
In Android, you could use InputDevice.
InputDevice: https://developer.android.com/reference/android/view/InputDevice
You could try the code below:
int[] devicesIds = InputDevice.GetDeviceIds();
foreach (var item in devicesIds)
{
//Check the device you want
InputDevice device = InputDevice.GetDevice(item);
//device.getName must to have virtual
var s = device.Name;
var b = device.KeyboardType;
}
You could use DependencyService to call this in Xamarin.Forms.
DependencyService: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction
thanks your reply, i try the way you suggested, but the returned value was not i want...
i found another post here, use that way and finally get the things i want,
here is my code to share:
InputMethodManager manager = (InputMethodManager)context.GetSystemService(Context.InputMethodService);
IList<InputMethodInfo> mInputMethodProperties = manager.EnabledInputMethodList;
IEnumerator<InputMethodInfo> imi = mInputMethodProperties.GetEnumerator();
while (imi.MoveNext())
{
InputMethodInfo inputInfo = imi.Current;
var iN = inputInfo.ServiceName;
}
Best Regards & thanks
Roll
I am new in DotnetNuke. Feel free to suggest me correct terminology.
I am working on DotnetNuke 7. I use C#. I have a table with 30 string fields and it can have maximum 50 records. Currently I am managing it using Database.
I think it's not much data and I should store it in local storage(if any) which can be faster than get data from database.
Can anybody suggest me if there is any local storage (temporary) and life of it in DotnetNuke?
Also please suggest me about my idea of switching over local storage rather database.
You could use the build-in DNN cache functionality.
using DotNetNuke.Common.Utilities;
public bool cacheExists(string key)
{
return DataCache.GetCache(key) != null;
}
public void setCache<T>(T value, string key)
{
DataCache.SetCache(key, value);
}
public T getCache<T>(string key)
{
return (T)DataCache.GetCache(key);
}
Usage:
string myString = "test";
Book myBook = new Book();
setCache(myString, "A");
setCache(myBook, "B");
string myStringFromCache = getCache<string>("A");
Book myBookFromCache = getCache<Book>("B");
I'm developing for WP8 and I need to store custom app settings. I found func 'ApplicationData' but it's not supported in WP8. Can you help me? I want to store permanent variables provided by user. For example:
Country = UA
News = 1
etc.
You can use Isolated Storage or ApplicationData.LocalSettings like this :
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Create a simple setting
localSettings.Values["exampleSetting"] = "Hello Windows";
// Read data from a simple setting
Object value = localSettings.Values["exampleSetting"];
if (value == null)
{
// No data
}
else
{
// Access data in value
}
// Delete a simple setting
localSettings.Values.Remove("exampleSetting");
Check this Link and also this Link
I'm trying to make a console application which accesses my SkyDrive account, however I cannot figure out how to get the Live SDK working.
I'm running on Live SDK version 5.4 and this is the code I'm trying to run - the loginResult.Status is always "Unknown":
private static async Task<LiveConnectClient> ConnectToLive()
{
LiveAuthClient authClient = new LiveAuthClient("my live ID");
var loginResult = await authClient.IntializeAsync(new[] { "wl.basic" });
if (loginResult.Status == LiveConnectSessionStatus.Connected)
return new LiveConnectClient(loginResult.Session);
return null;
}
A few things I'm not certain about (since the SDK documentation is somewhat lackluster at best):
"My live ID" - is this just my e-mail address used for my personal Live account, or is it some sort of application specific ID that you have to create somewhere ?
Is InitializeAsync the proper method to call for authenticating ? All examples I've found mention a "LoginAsync", but that method is not available in the DLL.
Is it even possible to use the SDK outside of Windows Phone / Metro apps ?
I got the following code to work using a SkyDriveClient downloaded from http://skydriveapiclient.codeplex.com/releases/view/103081
static void Main(string[] args)
{
var client = new SkyDriveServiceClient();
client.LogOn("YourEmail#hotmail.com", "password");
WebFolderInfo wfInfo = new WebFolderInfo();
WebFolderInfo[] wfInfoArray = client.ListRootWebFolders();
wfInfo = wfInfoArray[0];
client.Timeout = 1000000000;
string fn = #"test.txt";
if (File.Exists(fn))
{
client.UploadWebFile(fn, wfInfo);
}
}
I have a bunch of key/value pairs I'd like to cache for my WPF application. In Silverlight this is deliciously easy - I can just do:
IsolatedStorageSettings userSettings = IsolatedStorageSettings.ApplicationSettings;
wombat = (string)userSettings["marsupial"];
Is there anything like this in WPF? A wombat may not be a marsupial, now I think about it. Some work needed there.
Edit: I would like if I can to avoid serialising these to/from en masse, as there are going to be a very large number of them with large amounts of data in them (I'm caching web pages).
The IsolatedStorageSettings doesn't exist in the desktop version of the .NET Framework, it's only available in Silverlight. However you can use IsolatedStorage in any .NET application; just serialize a Dictionary<string, object> to a file in isolated storage.
var settings = new Dictionary<string, object>();
settings.Add("marsupial", wombat);
BinaryFormatter formatter = new BinaryFormatter();
var store = IsolatedStorageFile.GetUserStoreForAssembly();
// Save
using (var stream = store.OpenFile("settings.cfg", FileMode.OpenOrCreate, FileAccess.Write))
{
formatter.Serialize(stream, settings);
}
// Load
using (var stream = store.OpenFile("settings.cfg", FileMode.OpenOrCreate, FileAccess.Read))
{
settings = (Dictionary<string, object>)formatter.Deserialize(stream);
}
wombat = (string)settings["marsupial"];
If by WPF, you mean the full .Net runtime, then yes. There's a default Settings class created with the WPF project template.
Settings class
See this discussion
It doesn't exist in WPF but can easily be ported from Mono's moonlight implementation (http://vega.frugalware.org/tmpgit/moon/class/System.Windows/System.IO.IsolatedStorage/IsolatedStorageSettings.cs)
//Modifications at MoonLight's IsolatedStorageSettings.cs to make it work with WPF (whether deployed via ClickOnce or not):
// per application, per-computer, per-user
public static IsolatedStorageSettings ApplicationSettings {
get {
if (application_settings == null) {
application_settings = new IsolatedStorageSettings (
(System.Threading.Thread.GetDomain().ActivationContext!=null)?
IsolatedStorageFile.GetUserStoreForApplication() : //for WPF, apps deployed via ClickOnce will have a non-null ActivationContext
IsolatedStorageFile.GetUserStoreForAssembly());
}
return application_settings;
}
}
// per domain, per-computer, per-user
public static IsolatedStorageSettings SiteSettings {
get {
if (site_settings == null) {
site_settings = new IsolatedStorageSettings (
(System.Threading.Thread.GetDomain().ActivationContext!=null)?
IsolatedStorageFile.GetUserStoreForApplication() : //for WPF, apps deployed via ClickOnce will have a non-null ActivationContext
IsolatedStorageFile.GetUserStoreForAssembly());
//IsolatedStorageFile.GetUserStoreForSite() works only for Silverlight applications
}
return site_settings;
}
}
Note that you should also change the #if block at the top of that code to write
if !SILVERLIGHT
Also take a look at this for custom settings storage