WinRT Replacement for System.ComponentModel.TypeConverter

≡放荡痞女 提交于 2019-12-17 19:51:00

问题


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

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.


回答1:


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.

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

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

Option 3: You could create your own TypeConverter class.

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");
    }
}

Which would let you write code like this:

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



回答2:


Use IValueConverter interface.



来源:https://stackoverflow.com/questions/12495937/winrt-replacement-for-system-componentmodel-typeconverter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!