I have a WPF TextBox associated with the Distance view model number property through the Caliburn.Micro naming convention. I want to be able to customize the TextBox string format while maintaining the agreement binding established by Caliburn.Micro. How can I do it?
From my view model:
public double Distance { get { return _distance; } set { _distance = value; NotifyOfPropertyChange(() => Distance); } }
From my view:
<TextBox x:Name="Distance"/>
When the Distance value is non-zero, I want to display a number with a fixed set of decimal places, and when Distance is zero, I want the text box to be empty.
Using explicit binding, I can bind the TextBox.Text property to Distance , and then I can set StringFormat at the same time:
<TextBox x:Name="Distance" Text="{Binding Distance, StringFormat=0.000;;#}"/>
However, an explicit Text binding could then shorten the Caliburn.Micro naming convention binding. Is it possible to customize the string format without simultaneously setting the binding path to the TextBox.Text property TextBox.Text that I can fully rely on Caliburn.Micro to handle the Distance -to- TextBox binding?
source share