Beispiel #1
0
 private void RegisterAttached(UIElement uIElement)
 {
     if (uIElement.GetValue(FrameworkElement.NameProperty) is string name &&
         !string.IsNullOrEmpty(name) &&
         uIElement.IsVisible &&
         !helpObjects.ContainsKey(name))
     {
         var helpObject = new HelpObject(uIElement);
         helpObjects.Add(name, helpObject);
     }
 }
Beispiel #2
0
        private IEnumerable <ScriptObject> GetScripts(List <string> names)
        {
            //Binding registered controls and scripts
            var script = Script.Where(w => w.IsShow && names.Contains(w.NameHelpObject)).Select(s =>
            {
                s.HelpObject = helpObjects[s.NameHelpObject];
                return(s);
            });


            foreach (var itemScript in script)
            {
                yield return(itemScript);

                //Search item in ItemsControl
                if (itemScript.HelpObject.UIElement is ItemsControl itemsControl)
                {
                    HelpObject helpObjectItem = null;

                    double ic_w   = (double)itemsControl.GetValue(FrameworkElement.ActualWidthProperty);
                    double ic_h   = (double)itemsControl.GetValue(FrameworkElement.ActualHeightProperty);
                    Rect   icRect = itemsControl.TransformToVisual(this).TransformBounds(new Rect(0, 0, ic_w, ic_h));

                    int attempItem = 0;
                    foreach (var item in itemsControl.Items)
                    {
                        if (itemsControl.ItemContainerGenerator.ContainerFromItem(item) is UIElement uiItem && uiItem.IsVisible)
                        {
                            double ui_w       = (double)uiItem.GetValue(FrameworkElement.ActualWidthProperty);
                            double ui_h       = (double)uiItem.GetValue(FrameworkElement.ActualHeightProperty);
                            Rect   uiItemRect = uiItem.TransformToVisual(itemsControl).TransformBounds(new Rect(0, 0, ui_w, ui_h));

                            if (uiItemRect.X > 0 && uiItemRect.Y > 0)
                            {
                                helpObjectItem = new HelpObject(uiItem);
                                if (++attempItem >= 3)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (helpObjectItem != null)
                    {
                        if (itemScript.IsShowItem)
                        {
                            yield return(new ScriptObject()
                            {
                                NameHelpObject = $"{itemScript.NameHelpObject}_Item",
                                HelpObject = helpObjectItem,
                                Description = string.IsNullOrEmpty(itemScript.DescriptionItem) ? itemScript.Description : itemScript.DescriptionItem,
                                DescriptionTemplate = itemScript.DescriptionItemTemplate == null ? itemScript.DescriptionTemplate : itemScript.DescriptionItemTemplate,
                            });
                        }

                        //Search controls in Item
                        if (itemScript.Items != null)
                        {
                            foreach (var item in itemScript.Items.Where(w => w.IsShow))
                            {
                                var child = GetChildByName(helpObjectItem.UIElement, item.NameHelpObject);
                                if (child is UIElement uIElement)
                                {
                                    item.HelpObject = new HelpObject(uIElement);
                                    yield return(item);
                                }
                            }
                        }
                    }
                }
            }
        }