本文介绍了WinRT的置换System.ComponentModel.TypeConverter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它看起来并不像类型转换器可使用。有什么建议更换吗?

It doesn't look like TypeConverter is available to use. What is recommended to replace this?

我本来打算去创建自己的类型转换器类使用来取代它,但如果有新的或更好的方法在WinRT中做到这一点,我ð走这条路线。也有许多其他类,我需要重建;像所有的默认类型转换器。

I was going to go and create my own TypeConverter class to use to replace it, but if there is a new or better way in WinRT to do it, I'd go that route. There are also many other classes that I would need to recreate; like all the default type converters.

推荐答案

没有类型转换器在WinRT中和球队阶级还没有宣布任何计划包括在未来的版本。你有多种选择。

There is no TypeConverter class in the WinRT and the team has not announced any plans to include it in a future release. You have a number of options.

选项1:如果转换是必须要做的,作为一个数据绑定使用的IValueConverter 接口丹尼斯提到的部分。

Option 1: If the conversion is to be done as part of a data binding use the IValueConverter interface as Dennis mentioned.

选项2:如果你是该类型的创建者,你可以添加自己的明示或暗示的运营商支持的铸造:

Option 2: If you are the creator of the type you can add your own explicit or implicit operators to support casting:

http://msdn.microsoft.com /en-US/library/xhbhezf4(v=vs.80).aspx

http://msdn.microsoft.com /en-US/library/z5z9kes2(v=vs.80).aspx

方法3:您可以创建自己的类型转换器类

Option 3: You could create your own TypeConverter class.

方法4::您可以添加自己的扩展方法(我想这样做,如果不是部分的结合方式):

Option 4: (The way I'd do it if not part of a binding) You can add your own extension methods:

static public class ConverterExtensions
{
    static public string ToFixedString(this double value)
    {
        return value.ToString("D");
    }
}

这将让你写code是这样的:

Which would let you write code like this:

double d = 123.45;
string str = d.ToFixedString(); // str now equals "123"

这篇关于WinRT的置换System.ComponentModel.TypeConverter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 23:32