RadDateTimePicker +面膜数据录入 [英] RadDateTimePicker + Mask for Data Entry

查看:323
本文介绍了RadDateTimePicker +面膜数据录入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求:允许用户输入在######格式的日期,同时还必须从一个datepicker(假设输入的将是2000年后所有年份),选择它的能力,所以,例如,用户输入050513它成为2013年5月5日。或者,如果他们从的DatePicker选择它,提供相同的显示。他们还希望它在控件接收焦点,这样就可以很容易地覆盖任何预先存在的日期选择所有

Requirement: Allow user to enter date in the format of ###### while also have the ability to choose it from a DatePicker (assuming all years entered will be Post 2000.) So for example, user enters 050513 it becomes 5/5/2013. Or if they choose it from the DatePicker, provide the same display. They also want it to select all when the control receives focus so they can easily overwrite any pre-existing date.

我的尝试:我的XAML是不是我的C#,所以我试图让创意得到了真正织补接近,但没有雪茄,所以希望有人能填补空白强得多,但这里就是我得到了。我想我可以利用我所知道的关于 RadMaskedTextBox 并的 RadDateTimePicker 所以我交织它们的属性位(与想法,我可以只使用盒入境,和刚才的图标),但为测试目的而选择器是这样的;

What I tried: My xaml is much stronger than my c# so I tried to get creative and got really darn close but no cigar, so hoping someone could fill in the blanks but here's where I got. I figured I could leverage what I know about RadMaskedTextBox and RadDateTimePicker so I intertwined their properties a bit (with the idea I could just use the Box for entry, and the picker for just the icon) but for testing purposes it was something like this;

<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Center" >
    <telerik:RadMaskedTextBox x:Name="radMTB"
             Value="{Binding SelectedDate, Mode=TwoWay, 
                     ElementName=radDP}" 
             MaskType="DateTime"
             Mask="d" SelectionOnFocus="SelectAll" />                
    <telerik:RadDateTimePicker x:Name="radDP" 
             InputMode="DatePicker" 
             SelectedDate="{Binding SelectedDate, Mode=TwoWay, ElementName=radMTB}"/>
</StackPanel>

这只是一个事实,即它仍然要求他们键入完整的日期与斜线的伟大工程。所以我改变了MaskType为标准带口罩=## / ## / ## \2\0将20,所以他们能进入像121212,并成为2012年12月12日吗?以为我拥有它,直到我试图传递值关闭到的DatePicker。我绑定将selectedDate上选取器 TextWithLiterals 以得到显示值,没有运气。试图Display.Text,Display.Value,只是文本,只是价值。它不会与任何人合作,过于绑定,并通过关闭的DatePicker的工作...

This works great except for the fact that it still requires them to type the whole date with slashes. So I changed the MaskType to Standard with a Mask="##/##/\2\0##" to insert the "20" so they could enter like 121212 and it become 12/12/2012 right? Thought I had it until I tried to pass the value off to the DatePicker. I Bound the SelectedDate on the Picker to TextWithLiterals to get the display value, no luck. Tried Display.Text, Display.Value, just Text, just Value. It wouldn't work with any of them to bind too and pass off to the DatePicker to work...

所以我想我的问题是,我还可以绑定到该文字显示在某种程度上,使只使用XAML这项工作?或 ParseDateTimeValue 代码必然要求 RadDateTimePicker ?如果是这样,可能有人请分享一些知识,并帮助一个人出来呢?还是有另一种方式一起满足要求的追捧?这不能是第一次在此已经到来了?

So I guess my question is, can I still bind to that literal display somehow and make this work using only xaml? Or is ParseDateTimeValue code inevitably required for the RadDateTimePicker? If so, could someone please share some knowledge and help a guy out with it? Or is there another way all together to fulfill the sought after requirements? This cant be the first time this has come up?

感谢您阅读两种方式与欢呼!

Thanks for reading either way and cheers!

推荐答案

。它与DateTime值相当多的灵活

Instead of using RadMaskedTextBox, trying using Telerik's RadMaskedDateTimeInput. It is quite a bit more flexible with DateTime values.

<telerik:RadMaskedDateTimeInput x:Name="radMTB1"
                                IsClearButtonVisible="False"
                                FormatString="{}{0:M/d/yyyy}"
                                Mask="MMddyy"
                                SelectionOnFocus="SelectAll"
                                Value="{Binding SelectedDate, Mode=TwoWay, ElementName=radDP2}" />



更多信息:的 http://www.telerik.com/help/silverlight/radmaskedinput-features-controls-datetime.html

这篇关于RadDateTimePicker +面膜数据录入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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