I am trying to implement everything I can with MVVM rather than code behind, but if I have many objects that I need to access when the entry changes, I don't know how to do it well if at all.
Xaml:
<Entry x:Name="UpdatedCost"
TextChanged="UpdatedCost_TextChanged"/>
<Label x:Name="PriceDifLabel"/>
<Entry x:Name="CurrentCost"
Text="2.5"/>
<Entry x:Name="CurPriceUpdatedCostProfit"
Text="22%"/>
Code-Behind:
private void UpdatedCost_TextChanged(object sender, TextChangedEventArgs e)
{
if (double.TryParse(e.NewTextValue, out double UpdatedCost))
{
double diff = UpdatedCost - double.Parse(CurrentCost.Text);
string sign = diff > 0 ? "+" : "";
PriceDifLabel.Text = "(" + sign + string.Format("{0:0.0}", diff) +")";
PriceDifLabel.TextColor = diff > 0 ? Color.Red : Color.Green;
PriceDifLabel.BackgroundColor = Color.Yellow;
CurPriceUpdatedCostProfit.Text = ((int)((double.Parse(CurrentPrice.Text) - UpdatedCost) /
double.Parse(CurrentPrice.Text) * 100)).ToString() + "%";
}
}
I would highly appreciate as detailed help as possible converting this method to MVVM implementation. If it is relevant, my view model is implementing BaseViewModel of MvvmHelpers.
Thank you very much!
CurrentPrice.Text
? Is it a constant? And iscurrentcost.text
also a constant?