How can I format this textbox to GBP currency, like 0.00?:`
private void textBox_LostFocus(object sender, RoutedEventArgs e)
{
double amount = 0.0d;
if (Double.TryParse(textBox.Text, NumberStyles.Currency, null, out amount))
{
textBox.Text = amount.ToString("C");
}
}
That code is rupees but I was just testing it. I couldnt reall find anything much useful. The Textbox xaml:
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="51" Margin="10,461,0,0" TextWrapping="Wrap" Text="{Binding TotalValue}" VerticalAlignment="Top" Width="120" KeyDown="textBox_KeyDown" TextChanged="textBox_TextChanged_1" LostFocus="textBox_LostFocus"/>
The value right now is just something like 1.5 how can it be made to 1.50?
The TotalValue should be set to the formated currency.
private double totalValue;
public double TotalValue
{
get { return totalValue; }
set
{
totalValue = value;
OnPropertyChanged("TotalValue");
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Menu.PassedData data = e.Parameter as Menu.PassedData;
if (data != null) //If data is not 0
{
PassedData.Add(data); //Increment data in list view
double tempTotalValue = 0;
foreach (var record in PassedData)
{
tempTotalValue = tempTotalValue + record.Value;
}
TotalValue = tempTotalValue;
}
}