Is the a property in XamDateTimeInput that select all the text when the control gain focus(by tab navigation or with a mouse click)?
Hello Santiago,
There does not exist a property that determines whether or not the XamDateTimeInput control should select everything when it gets focus, but there is a SelectAll method on the control. I would recommend that you invoke this method when handling the GotFocus or GotKeyboardFocus event of the XamDataTimeInput.
It may be possible that you run into a timing issue here, and so if invoking this method does nothing, I would recommend invoking this method inside of a Dispatcher.BeginInvoke action, like so:
Dispatcher.BeginInvoke(new Action(() => { myDateInput.SelectAll(); }));
I hope this helps. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hi Andrew:
I tried this,
I create a class XamDateTimeInputExtensions that extends XamDateTimeInput
then I create a
DependencyProperty SelectAllOnFocusProperty = DependencyProperty.RegisterAttached( "SelectAllOnFocus", typeof(bool), typeof(XamDateTimeInputEx), new PropertyMetadata(true, SelectAllOnFocusPropertyChanged));
private static void SelectAllOnFocusPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var dateTimeInput = d as XamDateTimeInput; if (dateTimeInput == null) return; if ((bool)e.NewValue) { dateTimeInput.GotFocus += ( s, a ) => { dateTimeInput.SelectAll(); }; dateTimeInput.GotKeyboardFocus += (s, a) => { dateTimeInput.SelectAll(); }; } } public static void SetSelectAllOnFocus(DependencyObject obj, bool value) { obj.SetValue(SelectAllOnFocusProperty, value); } public static bool GetSelectAllOnFocus(DependencyObject d) { return (bool)d.GetValue(SelectAllOnFocusProperty); }
so I can add that property to my XamDateTimeInput in my Xaml but it does not detect the Property when I added to my control in the Xaml
do you have any idea why?or is there a better way to do it?
It appears that you have defined an attached property rather than an actual "Dependency" property in this case. This can be seen from the "RegisterAttached" method that is being called. To use this with your XamDateTimeInput, you would need to write something along the lines of the following:
<ig:XamDateTimeInput local:XamDateTimeInputEx.SelectAllOnFocus="true" />
Rather than doing this, I would recommend that you define your property like so, as this should allow you to access it directly from the XamDateTimeInputEx control:
public bool SelectAllOnFocus{ get { return (bool)GetValue(SelectAllOnFocusProperty); } set { SetValue(SelectAllOnFocusProperty, value); }} public static readonly DependencyProperty SelectAllOnFocusProperty =DependencyProperty.Register("SelectAllOnFocus", typeof(bool), typeof(XamDateTimeInputEx), new PropertyMetadata(true, SelectAllOnFocusPropertyChanged));