Last active
October 15, 2019 18:45
-
-
Save ankittyagii/11e43cc4c18e26dc93bcb595ebea6591 to your computer and use it in GitHub Desktop.
Xamarin Essentials
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
//UnitConverterPageViewModel | |
private string _kilometers; | |
public string Kilometers | |
{ | |
get { return _kilometers; } | |
set | |
{ | |
SetProperty(ref _kilometers, value); | |
} | |
} | |
public DelegateCommand<object> ConvertToKilometer { get; set; } | |
public UnitConverterPageViewModel() | |
{ | |
ConvertToKilometer = new DelegateCommand<object>(ToKilometers); | |
} | |
private void ToKilometers(object Miles) | |
{ | |
_kilometers = UnitConverters.MilesToKilometers(Convert.ToDouble(Miles)).ToString(); | |
RaisePropertyChanged("Kilometers"); | |
} | |
//UnitConverterPage | |
public partial class UnitConverterPage : ContentPage | |
{ | |
UnitConverterPageViewModel objUnitConverterViewModel; | |
public UnitConverterPage() | |
{ | |
InitializeComponent(); | |
this.BindingContext = objUnitConverterViewModel = new UnitConverterPageViewModel(); | |
} | |
private void Entry_TextChanged(object sender, TextChangedEventArgs e) | |
{ | |
if(e.OldTextValue!=null) | |
{ | |
return; | |
} | |
if (e.NewTextValue != null) | |
{ | |
double textValue=Convert.ToInt64(e.NewTextValue); | |
objUnitConverterViewModel.ConvertToKilometer.Execute(textValue); | |
} | |
} | |
} | |
//Xaml | |
<StackLayout Margin="20"> | |
<Label Text="Miles" ></Label> | |
<Entry Text="{Binding Miles}" TextChanged="Entry_TextChanged"/> | |
<Label Text="Killometers"/> | |
<Label Text="{Binding Kilometers}"/> | |
</StackLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment