Friday, May 24, 2019
If Previewer not showing
Right click on .Android solution- Options-Androidapplication-then make sure minimum target coincides with SDK manager installed under Tools.
Saturday, May 11, 2019
Tuesday, May 7, 2019
How to add and use photos in Xamarin forms
- On the main Xamarin project. Right click-add folder-name it. Put your photos in there.
- Right click on photo - select Build Action - Then Embedded Resource.
- Add photo into IOS and Android projects ---
- Right click on photo and select Copy.
Adding the photo into IOS and Android
so the photo will show up on IOS and Android OS
- Go to IOS/Android Project.
- Scroll to Resources. Right click on Resources.(on Android inside Resources-right click drawable)
- Click paste. (On IOS, right click image-Select BundleResource)
In Xaml file
- <Image Source="" x:Name="MyImage"/> //MyImage is name to access it from c#
In C# file
- MyImage.Source = ImageSource.FromFile("logo.jpg"); //logo.jpg is name of file
Monday, May 6, 2019
How to store user settings? Using xam.plugins.setting - Xamarin forms
Using a plugin from Nuget
public static class Settings
{
private static ISettings AppSettings
{
get
{
return CrossSettings.Current;
}
}
#region Setting Constants
//variable naming
//"SettingsKey" is always a string that is a unique ID that will be stored in the device to //access constructor GeneralSettings name it something the describes what you are storing
To save it: use the syntax below to save the data in Save button c file.
Use Settings is the file name where the code behind of get and sets.
Drain1LocationSettings is the GeneralSettings
EntryorPicker is in xaml file where the user enters the data needs to be save.
Settings.GeneralSettings = EntryorPicker;
To display the saved data: go to page or file where you want the saved data to be displayed then enter format syntax below
Labelofsavedata.Text = Settings.GeneralSettings;
https://www.youtube.com/watch?v=7DFCMm_4Nro
To clear IOS emulator settings:
delete app from emulator, clean all, then re run app.
http://bsubramanyamraju.blogspot.com/2018/04/appsettings-how-to-store-user-settings.html
- Right click on your project-click add Nuget Packages. Type xam.plugins.setting on search. Click on it and Add package.
- Add it on your Android project files and IOS project files perform step 1.
- Make a folder called Helpers(or any folder name you want some uses Util- on the solution project then - Create a new file called Settings.cs (empty class file)
- Copy and paste from readme.txt
// Helpers/Settings.cs
using Plugin.Settings;
using Plugin.Settings.Abstractions;
//$rootnamespace$ is the name of your project followed by where the file is stored
using Plugin.Settings;
using Plugin.Settings.Abstractions;
//$rootnamespace$ is the name of your project followed by where the file is stored
// in this case it's in Helpers folder
namespace $rootnamespace$.Helpers
{
/// <summary>
/// This is the Settings static class that can be used in your Core solution or in any
/// of your client applications. All settings are laid out the same exact way with getters
/// and setters.
/// </summary>
{
/// <summary>
/// This is the Settings static class that can be used in your Core solution or in any
/// of your client applications. All settings are laid out the same exact way with getters
/// and setters.
/// </summary>
public static class Settings
{
private static ISettings AppSettings
{
get
{
return CrossSettings.Current;
}
}
#region Setting Constants
//variable naming
//"SettingsKey" is always a string that is a unique ID that will be stored in the device to //access constructor GeneralSettings name it something the describes what you are storing
ie. NameKey, EmailKey; "name_key", "email_key"
private const string SettingsKey = "settings_key";
private static readonly string SettingsDefault = string.Empty;
#endregion
//contructor to get and set the Settings to be stored. Name the constructor something the describes what you are storing. It will be called on the Page where you want to use it.
private static readonly string SettingsDefault = string.Empty;
#endregion
//contructor to get and set the Settings to be stored. Name the constructor something the describes what you are storing. It will be called on the Page where you want to use it.
//ie NameSettings, EmailSettings
public static string GeneralSettings
{
get
{
{
get
{
//SettingsKey is the string from the const unique name variable above
return AppSettings.GetValueOrDefault(SettingsKey, SettingsDefault);
}
set
{
AppSettings.AddOrUpdateValue(SettingsKey, value);
}
}
}
}
return AppSettings.GetValueOrDefault(SettingsKey, SettingsDefault);
}
set
{
AppSettings.AddOrUpdateValue(SettingsKey, value);
}
}
}
}
Now to use the Settings.cs - you need include that namespace in the file where you want to use it. ie
//need to use namespace from where settings were SET to access it and use it to store user input. roosspace is name of your project.
using $rootnamespace$.Helpers;
To save it: use the syntax below to save the data in Save button c file.
Use Settings is the file name where the code behind of get and sets.
Drain1LocationSettings is the GeneralSettings
EntryorPicker is in xaml file where the user enters the data needs to be save.
Settings.GeneralSettings = EntryorPicker;
To display the saved data: go to page or file where you want the saved data to be displayed then enter format syntax below
Labelofsavedata.Text = Settings.GeneralSettings;
https://www.youtube.com/watch?v=7DFCMm_4Nro
To clear IOS emulator settings:
delete app from emulator, clean all, then re run app.
http://bsubramanyamraju.blogspot.com/2018/04/appsettings-how-to-store-user-settings.html
Subscribe to:
Comments (Atom)
