Skip to content

Instantly share code, notes, and snippets.

Last active Apr 12, 2016
What would you like to do?
Xamarin Develop Gist
menuGroupMain.Add(new MenuItem("Events", typeof(EventPage), '\uf009'));
//Add a page EventPage
//a public property with get and set and initial value
public ClockStatus currentClockStatus { get;private set;} = ClockStatus.Invalid;
//If I understand your "I just want to fill them automatically" comment correctly,
//you want to create a new Child object that's populated with the values of the Parent,
//with default values for the new properties. Best way to do that is to create a constructor that copies the values:
public class Parent
public string FirstName {get; set;}
public string LastName {get; set;}
public string City {get; set;}
public class Child : Parent
public string PhoneNumber {get; set;}
public string MobileNumber {get; set;}
public Child (Parent parentToCopy)
this.FirstName = parentToCopy.FirstName;
this.LastName = parentToCopy.LastName;
this.City = parentToCopy.City;
this.PhoneNumber = string.Empty; // Or any other default.
this.MobileNumber = string.Empty;
//Now you can use LINQ, like the answers above, to create a Child out of each Parent:
List<Child> lstChild = lstParent.Select(parent => new Child(parent)).ToList();
//Note that this is very similar to @daryal's answer,
//but wraps the parent-to-child copying logic inside the constructor,
//rather than having it outside in the new Child() call.
//1 encapsulate the method into the ItemRepository
<Label Grid.Column="1"
VerticalTextAlignment="Center" >
Text="&#xf075; "
FontSize="{StaticResource BaseFontSize}"
ForegroundColor="{StaticResource AccentColor}"
FontFamily="{x:Static artina:FontAwesome.FontName}" />
FontSize="{StaticResource BaseFontSize}"
ForegroundColor="White" />
//map Dto to model
//1 source =>2 des
var config = new MapperConfiguration (cfg => cfg.CreateMap<ClockDeviceDto, ClockDevice > ());
var mapper = config.CreateMapper ();
clockDevices = mapper.Map<IEnumerable<ClockDeviceDto>, IEnumerable<ClockDevice>> (clockDeviceDtos);
var notificator = DependencyService.Get<IToastNotificator>();
Device.BeginInvokeOnMainThread (async () => {
bool tapped = await notificator.Notify(ToastNotificationType.Error,
"Error", "Response Status Code is not successful!", TimeSpan.FromSeconds(2));
//UI thread
var notificator = DependencyService.Get<IToastNotificator>();
Device.BeginInvokeOnMainThread (async () => {
//How to use the key-value in Xamarin Form
//set for the key
public static string dictPolicyStepoutAllowance{ get; } = "dictPolicyStepoutAllowance";
public static string dictPolicyHeartbeatInterval{ get; } = "dictPolicyHeartbeatInterval";
//Get the value of properties
var app = Application.Current as App;
if (app == null) return;
//whether the key exist
app.Properties.ContainsKey (App.dictIsRegister)
//get the value of the key
var x = (bool)app.Properties [App.dictIsRegister]
var y = (string)app.Properties [App.key]
//Set the value of properties
app.Properties[App.dictUserDeviceName] = _userDevice.deviceName;
app.Properties[App.dictUserDeviceMac] = _userDevice.deviceMAC;
app.Properties[App.dictUserDeviceType] = _userDevice.deviceType;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment