Let's say my application doesn't support culture es-MX so when this is the current setting on the phone I'd like to set the culture to es-ES. Is this possible to do in Windows Phone and if so how?
This is definitely possible!
See this list for cultures and their identifiers
So for example in the App.xaml.cs constructor you could access Thread.CurrentThread.CurrentCulture to determine the actual culture the app is running in. Now if you want to force the UI to use another culture you can do that by setting the CurrentUICulture. For example:
if (Thread.CurrentThread.CurrentCulture.Name.Equals("es-MX"))
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("es-ES");
}
Related
I have a .NET application that interacts with Outlook like this:
Microsoft.Office.Interop.Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem item = app.CreateItem((Microsoft.Office.Interop.Outlook.OlItemType.olMailItem));
item.PropertyAccessor.SetProperty(PsInternetHeaders + Foobar, 1031);
item.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
item.To = "a#test.com;b#test.com;c#test.com";
item.BCC = "cc#test.com";
item.Body = "Hello There!";
item.Display();
Be aware that I need to access the "PropertyAccessor" property.
In a normal environment this runs fine, but in a "secure" enviroment with this registry keys in place it just fails with Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)):
[HKEY_CURRENT_USER\Software\Policies\Microsoft\office\16.0\outlook\security]
"PromptOOMAddressBookAccess"=dword:00000000
"AdminSecurityMode"=dword:00000003
"PromptOOMAddressInformationAccess"=dword:00000000
Outlooks security model seems to have a "trustedaddins" list, but I'm not really sure if this applies to "external applications" as well and that exactly I need to register unter TrustedAddins (see here).
My main question would be: Can I just register and foobar.exe unter trustedaddins or is this not possible at all?
I know that I could lower or disable the security stuff, but this is not my choice ;)
Your only options are listed at How to avoid Outlook Security Alert when sending Outlook message from VBScript?
You also might want to set PsInternetHeaders properties to strings only, not ints.
I'm coding a bot in two languages (en, es) which will always be accessed via DirectLine API.
The documentation says that:
The localization language is determined by the current thread's CurrentUICulture and CurrentCulture.
What is the proper way to pass the language to the BOT from the DirectLine API, so can be getted by CurrentCulture?
I haven't found out a proper way to do it, but I use a workaround.
When you give your user an ID, add the culture. Like this:
id: 'en-'+ idGeneratedByYou
Then from the controller:
var culture = activity.From.Id.Split('-')[0];
Finally, do a switch and depending it is en or es:
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("es-ES");
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("es-ES");
I know this is not the best way, but maybe it will work out for you.
I have a simple Xamarin Forms app. I've now got a simple POCO object (eg. User instance or an list of the most recent tweets or orders or whatever).
How can I store this object locally to the device? Lets imagine I serialize it as JSON.
Also, how secure is this data? Is it part of Keychains, etc? Auto backed up?
cheers!
You have a couple options.
SQLite. This option is cross-platform and works well if you have a lot of data. You get the added bonus of transaction support and async support as well. EDIT: In the past I suggested using SQLite.Net-PCL. Due to issues involving Android 7.0 support (and an apparent sunsetting of support) I now recommend making use of the project that was originally forked from: sqlite-net
Local storage. There's a great nuget that supports cross-platform storage. For more information see PCLStorage
There's also Application.Current.Properties implemented in Xamarin.Forms that allow simple Key-Value pairs of data.
I think you'll have to investigate and find out which route serves your needs best.
As far as security, that depends on where you put your data on each device. Android stores app data in a secure app folder by default (not all that secure if you're rooted). iOS has several different folders for data storage based on different needs. Read more here: iOS Data Storage
Another option is the Xamarin Forms settings plugin.
E.g. If you need to store a user instance, just serialize it to json when storing and deserialize it when reading.
Uses the native settings management
Android: SharedPreferences
iOS: NSUserDefaults
Windows Phone: IsolatedStorageSettings
Windows RT / UWP: ApplicationDataContainer
public User CurrentUser
{
get
{
User user = null;
var serializedUser = CrossSettings.Current.GetValueOrDefault<string>(UserKey);
if (serializedUser != null)
{
user = JsonConvert.DeserializeObject<User>(serializedUser);
}
return user;
}
set
{
CrossSettings.Current.AddOrUpdateValue(UserKey, JsonConvert.SerializeObject(value));
}
}
EDIT:
There is a new solution for this. Just use Xamarin.Essentials.
Preferences.Set(UserKey, JsonConvert.SerializeObject(value));
var user= JsonConvert.DeserializeObject<User>(Preferences.Get(UserKey, "default_value");
Please use Xamarin.Essentials
The Preferences class helps to store application preferences in a key/value store.
To save a value:
Preferences.Set("my_key", "my_value");
To get a value:
var myValue = Preferences.Get("my_key", "default_value");
If you want to store a simple value, such as a string, follow this Example code.
setting the value of the "totalSeats.Text" to the "SeatNumbers" key from page1
Application.Current.Properties["SeatNumbers"] = totalSeats.Text;
await Application.Current.SavePropertiesAsync();
then, you can simply get the value from any other page (page2)
var value = Application.Current.Properties["SeatNumbers"].ToString();
Additionally, you can set that value to another Label or Entry etc.
SeatNumbersEntry.Text = value;
If it's Key value(one value) data storage, follow below code
Application.Current.Properties["AppNumber"] = "123"
await Application.Current.SavePropertiesAsync();
Getting the same value
var value = Application.Current.Properties["AppNumber"];
Does anyone know how to register for Locale or TimeZone changes in a WINRT application?
You can use a background task to run when TimeZone changes.
var builder = new BackgroundTaskBuilder();
builder.Name = "YourTask";
builder.TaskEntryPoint = "The.Background.Task.Implementation.Class";
builder.SetTrigger( new SystemTrigger( SystemTriggerType.TimeZoneChange, false ) );
builder.Register();
The main problem you will probably face however is that in Windows 8 the timezone will return the old value until the next reboot (although I'm not sure if that changed for Windows 8.1). The only way then to access the real new values for TimeZone is to use Win32 API – specifically this function http://msdn.microsoft.com/en-us/library/windows/apps/ms724421(v=vs.85).aspx
I want the user to choose his language in my app so if he chooses a different Language (because he wants to test his skills in other languages) than the Phone default language, I want all my globalized Strings to be changed during runtime.
Is there the possibility to override the culture Info in c# for wp7 or wp8 for the runtime of current app?
In App.xaml.cs, in the InitializePhoneApplication method:
private void InitializePhoneApplication()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
.......
}
Be sure to edit you .csproj project file to set support for the languages you want to use in the SupportedCultures tag:
<SupportedCultures>en;fr-FR</SupportedCultures>