Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Unable to set focus to datepicker using attached property in wpf

Unable to set focus to datepicker using attached property in wpf

Scheduled Pinned Locked Moved WPF
csharpwpflinqdesignannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dashingsidds
    wrote on last edited by
    #1

    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 DatePicker

    using 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

    P 1 Reply Last reply
    0
    • D dashingsidds

      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 DatePicker

      using 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

      P Offline
      P Offline
      PumbaPumba
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups