I have to display a decimal representing a price.
If the price is in British Pence or Yen, it needs to display it to 4 decimal places, otherwise it needs to display it to 6 decimal places.
The currency is encoded as a string, and will be GBp
or YEN
or other (e.g. EUR
). Both the currency string and the price are in the ViewModel. I am using MVVM.
I am wondering if its possible to select the correct string format using nothing but pure XAML?
Easy peasy with a couple of DataTriggers:
For the above example I've made a class called
Currency
which has astring
propertyName
. The VM has anObservableCollection<Currency>
calledCurrencies
, an instance ofCurrency
calledSelectedCurrency
, and adecimal
property calledPrice
.