I'm working on a simple UWP app. I want to make it possible for the user to enter some monetary value, in this case an hourly rate. The data type is decimal. Here's the property from the viewmodel:
private decimal hourly;
public decimal Hourly
{
get => salaryConvUS.Hourly;
set
{
Set(ref hourly, value); //Template10 method
salaryConvUS.Hourly = hourly;
}
}
And here's the XAML code:
<TextBox x:Name="HourlyTextBox"
Text="{x:Bind ViewModel.Hourly, Mode=TwoWay}"
Style="{StaticResource CommonTextboxStyle}" />
It would seem to me to be pretty straight forward, but I'm getting an error that says,
App.InitializeComponent.AnonymousMethod__3_0(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e)"
in the App.g.i.cs file. I've searched for this error, but what I found didn't apply to this situation.
The one thing that might have something to do with it is a problem I know that Windows 8 applications had, in that you couldn't bind something like a textbox to a decimal data type. You had to do some sort of conversion. Is that what's going on here in UWP?
TextBlock holds a string value. So you can't bind decimal value with a TextBlock directly.
Use the ToString()
method to bind correctly.
You can use something like this -
private string hourly;
public string Hourly
{
//Your Algorithm
}