示例#1
0
        /// <summary>
        /// Subscribes to Detail's View LayoutUpdated event and sets focus on the first field editor when the event occurs.
        /// After the LayoutUpdated event occurs the Details View should be in the state that all field editors are displayed, 
        /// so it is possible to set focus on the first field editor.
        /// </summary>
        /// <param name="detailsView">View for the Details ViewModel.</param>
        private static void SubscribeDetailsLayoutUpdated(UserControl detailsView)
        {
            var sections = detailsView.GetChildrenByName("Sections").FirstOrDefault() as FrameworkElement;

            if (sections == null)
            {
                return;
            }

            EventHandler updateHandler = null;

            updateHandler = (o, args) =>
                {
                    sections.LayoutUpdated -= updateHandler;

                    var children = sections.GetChildrenByType<UserControl>();

                    if (children.Count > 1)
                    {
                        Control item = null;

                        for (var i = 1; i < children.Count; i++)
                        {
                            item = children[i].GetChildrenByType<Control>().FirstOrDefault(c => c.IsFocusable());

                            if (item != null)
                            {
                                item.Focus();
                                break;
                            }
                        }
                    }
                };

            sections.LayoutUpdated += updateHandler;
        }