I am using Caliburn.Micro.
In my View I have a TextBox
Binded to double X
and a Button
which alters the value of X in my ViewModel.
public void ButtonPressed()
{
X = AnObject.GetDouble;
NotifyOfPropertyChange(() => X);
}
public double X { get; set; }
My Goal is to limit the number of decimals that is displayed. This number, is configurable in the application and therefore available as a Property of AnObject. Therefore I have defined a IMultiValueConverter
:
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return String.Format(values[1].ToString(), values[0]);
}
and defined my TextBox as follows:
<TextBox>
<TextBox.Text>
<MultiBinding Converter="{StaticResource coordinateConverter}" >
<Binding Path="X" />
<Binding Path="AnObject.FormatNumberOfDecimals" />
</MultiBinding>
</TextBox.Text>
</TextBox>
What works: The initial value of X, zero, is being formatted correctly.
What doesn't work: When the button is pressed, the new value is not being displayed in the TextBox.
Suggestions that don't use IMultiValueConverter are welcome as well.