I have an entry with amounts where i would like to present it with two decimals when its not focused and as-is when focused.
I tried to do this using Triggers on my Entry.
It is not working. For some reason, the Default value on my Binding is set, when the Property is triggered and the Binding is changed
Editing and entered the value 12
Default value is set when the formatting binding is applied.
<Entry Grid.Column="1" Text="{Binding Text}">
<Entry.Triggers>
<Trigger TargetType="Entry" Property="IsFocused" Value="True">
<Setter Property="Text" Value="{Binding Text}" />
</Trigger>
<Trigger TargetType="Entry" Property="IsFocused" Value="False">
<Setter Property="Text" Value="{Binding Text, StringFormat='{0:N2}'}" />
</Trigger>
</Entry.Triggers>
</Entry>
I am referencing a Bindable Property
public static readonly BindableProperty TextProperty =
BindableProperty.Create(nameof(Text), typeof(decimal), typeof(MainPage), defaultValue: 0m);
public decimal Text
{
get { return (decimal)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
This could be somewhat related to https://github.com/xamarin/Xamarin.Forms/issues/1412
Does anyone have experience with a solution like this ? Suggestions for ways to work around this.