Skip to content

Instantly share code, notes, and snippets.

@ankittyagii
Last active October 15, 2019 18:45
Show Gist options
  • Save ankittyagii/11e43cc4c18e26dc93bcb595ebea6591 to your computer and use it in GitHub Desktop.
Save ankittyagii/11e43cc4c18e26dc93bcb595ebea6591 to your computer and use it in GitHub Desktop.
Xamarin Essentials
//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