WinRT Replacement for System.ComponentModel.TypeConverter(System.ComponentModel.TypeConverter 的 WinRT 替换)
问题描述
它看起来不像 TypeConverter 可以使用.建议用什么替换它?
It doesn't look like TypeConverter is available to use. What is recommended to replace this?
我本来打算创建自己的 TypeConverter 类来替换它,但如果 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 中没有 TypeConverter 类,团队尚未宣布任何计划将其包含在未来的版本中.您有多种选择.
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:如果要将转换作为数据绑定的一部分进行,请使用 Dennis 提到的 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:您可以创建自己的 TypeConverter 类.
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");
}
}
这会让你编写这样的代码:
Which would let you write code like this:
double d = 123.45;
string str = d.ToFixedString(); // str now equals "123"
这篇关于System.ComponentModel.TypeConverter 的 WinRT 替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:System.ComponentModel.TypeConverter 的 WinRT 替换
基础教程推荐
- C# 从 List<List<int>> 中删除重 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
