I have a WPF TextBox
that is bound to a view-model number property Distance
through Caliburn.Micro naming conventions. I want to be able to customize the TextBox
string format while preserving the convention binding that Caliburn.Micro has set up. How should I do that?
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
is non-zero, I want to display the number with a fixed set of decimals, and when the 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 the StringFormat
simultaneously:
<TextBox x:Name="Distance" Text="{Binding Distance, StringFormat=0.000;;#}"/>
However, the explicit Text
binding would then short-circuit the Caliburn.Micro naming convention binding. Is it possible to customize the string format without simultaneously having to set the binding path of the TextBox.Text
property, so that I can solely rely on Caliburn.Micro to handle the Distance
-to-TextBox
binding?