Last active
April 12, 2016 11:47
-
-
Save xinmeng1/6af0d4ed1e281efb161e08c4204cf487 to your computer and use it in GitHub Desktop.
Xamarin Develop Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1 encapsulate the method into the ItemRepository | |
App.Repository.DeleteAllClockDevice(); | |
App.Repository.SaveClockDevices(ClockDeviceList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Label Grid.Column="1" | |
HorizontalTextAlignment="Center" | |
VerticalTextAlignment="Center" > | |
<Label.FormattedText> | |
<FormattedString> | |
<FormattedString.Spans> | |
<Span | |
Text=" " | |
FontSize="{StaticResource BaseFontSize}" | |
ForegroundColor="{StaticResource AccentColor}" | |
FontFamily="{x:Static artina:FontAwesome.FontName}" /> | |
<Span | |
Text="2963" | |
FontSize="{StaticResource BaseFontSize}" | |
ForegroundColor="White" /> | |
</FormattedString.Spans> | |
</FormattedString> | |
</Label.FormattedText> | |
</Label> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () => { | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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