I have three textblocks whose text are bound to three different properties.
<TextBlock Style="{StaticResource textBlockStyle2}"
Text="{Binding Path=TWD,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged},
StringFormat={}{0:F1} M}" />
<TextBlock Style="{StaticResource textBlockStyle2}"
Text="{Binding Path=Alt,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged},
StringFormat={}{0:F1} M}" />
<TextBlock Style="{StaticResource textBlockStyle2}"
Text="{Binding Path=Dep,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged},
StringFormat={}{0:F1} M}" />
These are the properties in the viewmodel:
private double _TWD;
public double TWD
{
get { return _TWD; }
set { _TWD = value; OnPropertyChanged("TWD"); }
}
private double _Alt;
public double Alt
{
get { return _Alt; }
set { _Alt = value; OnPropertyChanged("Alt"); }
}
private double _Dep;
public double Dep
{
get { return _Dep; }
set { _Dep = value; OnPropertyChanged("Dep"); }
}
Now, these are in meters, which is what the 'M' is for in the StringFormat property of the textblocks. What I'm trying to do is, when I 'click' (via command) on a separate textblock (this will be inside of a button using a control template), I want to convert the values in the above textblocks to feet and add an 'F' after the value. Another click will convert it back to meters, and so on.
I was thinking about adding a command that just converted the values based on a bool isMeters
. However, the values in the textblock are constantly updated (every second) and I don't want to have to call the function every time the values change. Is there a simpler way I'm not thinking of to achieve this functionality?
Note:
1 meter = 3.2808 ft
1ft = 0.3048 meter