Reputation: 28255
We have an application that will be reading real world dimensions from the DB in milimetres, these values will then be presented to the user in WPF. Currently I'm using the following strategy when reading objects from the data store by multiplying MilimetresPrWpfUnit
in the following example.
public const double MilimetresPerInch = 25.4;
public const double WpfUnitsPerInch = 96;
public const double MilimetresPerWpfUnit
= WpfUnitsPerInch / MilimetresPerInch;
When loading and creating objects I'm currently converting as objects are being created, however this poses the problem that when the user selects an object on screen the size of that object needs to be converted back to the real world size, this isn't much of a problem but there is a lot of conversion going on.
Is there any utility in WPF to handle changing the unit size to metric? That might be the best solution.
The alternative is to create an IValueConverter
that will convert from/to metric units, though this I fear could have a performance impact.
Upvotes: 2
Views: 262
Reputation: 7653
Hey Brett, is your concern that there will be a performance hit for the conversion if you do it yourself? I dunno but if you think about it, whether this is automated by the framework or done by yourself, there will always be a performance hit for conversion. You really just need to work out at which point your data can be converted so that the conversion does not need to be replicated continually as you work with the data.
A few ways to approach this...
The IValueConverter method would definately be one way of tackling this, or you could write a method that converts the data to the metric you want when the data is being loaded, but all in all something like this is really a design specific scenario and something where one would need to see more of the code or get a more general explanation of the algorithm to make any proper recommendations.
Upvotes: 1