Unable to set focus to datepicker using attached property in wpf
-
Hi Experts, I have a custom datepicker with me and i am trying to set focus to this using attached property. I have the toolkit version 3.5.50211.1 which was released on Feb 2010. The focus is working fine when i do
DatePicker.Focus();
in my code. My custom datepicker code is as follows: -- My DatePickerusing System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Windows.Controls;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.ComponentModel;
using System.Windows.Controls.Primitives;namespace Guardian.PAS.PASFramework.UI.WPF
{
public class PASDatePicker : DatePicker
{
#region Attached Property/// <summary> /// Get of IsFocus Property. /// </summary> /// <param name="obj"></param> /// <returns></returns> public static bool GetIsFocus(DependencyObject obj) { return (bool)obj.GetValue(IsFocusProperty); } /// <summary> /// Set of IsFocus Property. /// </summary> /// <param name="obj"></param> /// <param name="value"></param> public static void SetIsFocus(DependencyObject obj, bool value) { obj.SetValue(IsFocusProperty, value); } public static readonly DependencyProperty IsFocusProperty = DependencyProperty.RegisterAttached( "IsFocus", typeof(bool), typeof(PASDatePicker), new UIPropertyMetadata(false, OnIsFocusPropertyChanged)); /// <summary> /// Property change event of IsFocused. /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnIsFocusPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var uie = (UIElement)d; if ((bool)e.NewValue) { // Don't care about false values. (uie as PASDatePicker).Focus(); } } #endregion }
}
I am using this datepicker in my code and tryin
-
Hi Experts, I have a custom datepicker with me and i am trying to set focus to this using attached property. I have the toolkit version 3.5.50211.1 which was released on Feb 2010. The focus is working fine when i do
DatePicker.Focus();
in my code. My custom datepicker code is as follows: -- My DatePickerusing System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Windows.Controls;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.ComponentModel;
using System.Windows.Controls.Primitives;namespace Guardian.PAS.PASFramework.UI.WPF
{
public class PASDatePicker : DatePicker
{
#region Attached Property/// <summary> /// Get of IsFocus Property. /// </summary> /// <param name="obj"></param> /// <returns></returns> public static bool GetIsFocus(DependencyObject obj) { return (bool)obj.GetValue(IsFocusProperty); } /// <summary> /// Set of IsFocus Property. /// </summary> /// <param name="obj"></param> /// <param name="value"></param> public static void SetIsFocus(DependencyObject obj, bool value) { obj.SetValue(IsFocusProperty, value); } public static readonly DependencyProperty IsFocusProperty = DependencyProperty.RegisterAttached( "IsFocus", typeof(bool), typeof(PASDatePicker), new UIPropertyMetadata(false, OnIsFocusPropertyChanged)); /// <summary> /// Property change event of IsFocused. /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnIsFocusPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var uie = (UIElement)d; if ((bool)e.NewValue) { // Don't care about false values. (uie as PASDatePicker).Focus(); } } #endregion }
}
I am using this datepicker in my code and tryin
Hi dashingsidds, Change it into normal dp. We normally use AttachedProperty when we have child elements. In this case no need of AttachedProperty. To-Resolve this issue: Ensure, the PropertyChanged is getting fired properly and/or PropertyChanged is not null. HTH