[英]DateTime XAML WinRT
Passing a string to the DependencyProperty
of a control that takes a DateTime
does not seem to be allowed: 似乎不允许将字符串传递给采用
DateTime
的控件的DependencyProperty
:
Cannot assign text value '00:00:00' into property 'StartTime' of type 'DateTime'
Is it just me or shouldn't this be possible? 只是我还是不应该这样吗? The workaround I suppose is to provide a IValueConverter to convert strings to DateTime objects.
我想解决方法是提供一个IValueConverter来将字符串转换为DateTime对象。 For Scheduler/Calender like controls this is a little annoying.
对于Scheduler / Calender这样的控件,这有点烦人。
Shed some light? 一些启发?
TypeConverter
isn't available in WinRT and while the platform seems to have some built in conversions for many UI types - this implicit conversion is not one of those. TypeConverter
在WinRT中不可用,尽管该平台似乎为许多UI类型提供了一些内置的转换-这种隐式转换不是其中之一。 You have a few options though. 您虽然有一些选择。
DateTime
property is bound to a DateTime
view model property. DateTime
属性绑定到DateTime
视图模型属性。 String
and do the conversions inside of your control - if you would typically initialize that property with a XAML string. String
类型,并在控件内部进行转换-如果通常使用XAML字符串初始化该属性。 It would also be worth it to append 'String' to the name of the property to make it clear that it's a string - eg 'StartDateString'. DateTime
and String
types - you could have properties of both types and synchronize them internally, making sure to prevent reentrancy in property change handlers. DateTime
和String
类型的控件-您可以同时拥有这两种类型的属性并在内部进行同步,请确保防止在属性更改处理程序中重新输入。 Object
and detect what type the values being set are to either set a DateTime
value directly, convert from String
or other types ( DateTimeOffset
, TimeSpan
, ...?) or throw for unsupported values. Object
类型,并检测要设置的值是直接设置DateTime
值,从String
转换还是其他类型( DateTimeOffset
, TimeSpan
,...?)的类型,或者抛出不支持的值。 Unfortunately until the Windows platform teams add support for TypeConverter
attribute - you don't have a pretty solution. 不幸的是,直到Windows平台团队添加对
TypeConverter
属性的支持-您还没有一个漂亮的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.