FocusFirstControl Behavior

Jun 4, 2012 at 3:41 PM

Hi Geert,

how about adding the following simple FocusFirstControl behavior for users which cannot use the DataWindow (like me)?

 

    public class FocusFirstControl : BehaviorBase<FrameworkElement>
    {
        public static readonly DependencyProperty FocusParentsFirstProperty =
            DependencyProperty.Register(
                "FocusParentsFirst", typeof(bool), typeof(FocusFirstControl), new PropertyMetadata(true));

        public bool FocusParentsFirst
        {
            get
            {
                return (bool)this.GetValue(FocusParentsFirstProperty);
            }

            set
            {
                this.SetValue(FocusParentsFirstProperty, value);
            }
        }

        protected override void OnAssociatedObjectLoaded(object sender, EventArgs e)
        {
	    base.OnAssociatedObjectLoaded(sender, e);
            this.AssociatedObject.FocusFirstControl(this.FocusParentsFirst);
        }
    }
many thanks!
Coordinator
Jun 4, 2012 at 3:42 PM

Seems like a good idea. I will add this ASAP (but very busy this week, probably not much work for Catel)

Coordinator
Jun 4, 2012 at 4:45 PM

Btw, the Focus does not work for you?

http://blog.catenalogic.com/post/2011/11/18/Behaviors-in-the-spotlight-Focus.aspx

Jun 4, 2012 at 5:33 PM

many thanks for adding it. FocusFirstControl seems to me a better choice in a windowed environment and it is easier to let the behavior find the first control for the focus.

Coordinator
Jun 5, 2012 at 6:13 PM

This feature is added, I will release a new nuget package tonight.

Jun 6, 2012 at 9:17 AM

Works perfectly! thanks