应该用于将现实世界的测量,WPF台什么样的策略? [英] What strategy should be used for converting real world measurements to WPF units?

查看:141
本文介绍了应该用于将现实世界的测量,WPF台什么样的策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有在milimetres将读真实世界的尺寸从DB的应用程序,这些值将是psented到在WPF用户$ P $。目前,我在下面的例子中相乘 MilimetresPrWpfUnit 读取数据存储对象时使用了以下策略。

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.

在WPF中的任何工具来处理不断变化的单元尺寸为公制?这也许是最好的解决方案。

Is there any utility in WPF to handle changing the unit size to metric? That might be the best solution.

另一种方法是创建一个的IValueConverter 将转换自/至公制单位,虽然这我担心这可能会影响性能。

The alternative is to create an IValueConverter that will convert from/to metric units, though this I fear could have a performance impact.

推荐答案

嘿布雷特,是您的关心,会有的转换性能的下降,如果你自己做的吗?我不知道,但如果你仔细想想,这是否是由框架或自动自己做的,总是会有一个性能损失进行转换。你真的只需要制定出点你的数据可以转换为这,这样的转换并不需要被不断复制,你的工作与数据。

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...

本的IValueConverter方法​​肯定会是解决这个的一种方式,或者你可以写一个数据到你想要的数据被加载时度量转换的方法,但所有的一切这样的事情实在是一个设计具体方案有什么东西,其中一个需要看到更多的code或获取算法的更一般的解释作出任何适当的建议。

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.

这篇关于应该用于将现实世界的测量,WPF台什么样的策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆