protected override async void Invoke(VisualElement sender)
        {
            if (Property == null)
            {
                throw new InvalidOperationException($"{nameof(Property)} may not be null");
            }

            if (Value == null)
            {
                throw new InvalidOperationException($"{nameof(Value)} may not be null");
            }

            TargetElement = TargetElement ?? sender ?? throw new ArgumentNullException(nameof(sender));

            Type targetElementType = TargetElement.GetType();

            PropertyInfo?propertyInfo = targetElementType.GetProperty(Property);

            if (propertyInfo == null)
            {
                throw new ArgumentException($"Could not find property {Property} in {targetElementType}");
            }

            Type propertyType = propertyInfo.PropertyType;

            if (propertyType != Value.GetType())
            {
                if (ConvertUsingXamlTypeConverter(propertyInfo, Value, out object?resultValue))
                {
                    Value = resultValue !;
                }
                else
                {
                    Value = ConvertUsingDotNetTypeConverter(propertyType, Value);
                }
            }

            if (Delay != null)
            {
                int delay = Convert.ToInt32(Delay, CultureInfo.InvariantCulture);
                await Task.Delay(delay);
            }

            propertyInfo.SetValue(TargetElement, Value);
        }
Пример #2
0
        public override void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            var removedDummyChild = ClearDummyChild();

            switch (child)
            {
            case XF.TemplatedPage childAsTemplatedPage:
                ShellControl.Items.Add(childAsTemplatedPage);     // Implicit conversion
                break;

            case XF.ShellContent childAsShellContent:
                ShellControl.Items.Add(childAsShellContent);     // Implicit conversion
                break;

            case XF.ShellSection childAsShellSection:
                ShellControl.Items.Add(childAsShellSection);     // Implicit conversion
                break;

            case XF.MenuItem childAsMenuItem:
                ShellControl.Items.Add(childAsMenuItem);     // Implicit conversion
                break;

            case XF.ShellItem childAsShellItem:
                ShellControl.Items.Add(childAsShellItem);
                break;

            default:
                throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support adding a child (child type is '{child.GetType().FullName}').");
            }
            // TODO: If this was the first item added, mark it as the current item
            // But this code seems to cause a NullRef...
            //if (removedDummyChild)
            //{
            //    ShellControl.CurrentItem = parentAsShell.Items[0];
            //}
        }
Пример #3
0
        public override void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            switch (child)
            {
            case XF.TemplatedPage childAsTemplatedPage:
                ShellSectionControl.Items.Add(childAsTemplatedPage);     // Implicit conversion
                break;

            case XF.ShellContent childAsShellContent:
                ShellSectionControl.Items.Add(childAsShellContent);
                break;

            default:
                throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support adding a child (child type is '{child.GetType().FullName}').");
            }
        }
Пример #4
0
        public virtual void RemoveChild(XF.Element child)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            var sectionToRemove = GetSectionForElement(child)
                                  ?? throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support removing a child (child type is '{child.GetType().FullName}').");

            ShellItemControl.Items.Remove(sectionToRemove);
        }
Пример #5
0
        public virtual void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            XF.ShellSection sectionToAdd = child switch
            {
                XF.TemplatedPage childAsTemplatedPage => childAsTemplatedPage,          // Implicit conversion
                            XF.ShellContent childAsShellContent => childAsShellContent, // Implicit conversion
                            XF.ShellSection childAsShellSection => childAsShellSection,
                            _ => throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support adding a child (child type is '{child.GetType().FullName}').")
            };

            if (ShellItemControl.Items.Count >= physicalSiblingIndex)
            {
                ShellItemControl.Items.Insert(physicalSiblingIndex, sectionToAdd);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but ShellItemControl.Items.Count={ShellItemControl.Items.Count}");
                ShellItemControl.Items.Add(sectionToAdd);
            }
        }
Пример #6
0
        public virtual void RemoveChild(XF.Element child)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            XF.ShellContent contentToRemove = child switch
            {
                XF.TemplatedPage childAsTemplatedPage => GetContentForTemplatePage(childAsTemplatedPage),
                XF.ShellContent childAsShellContent => childAsShellContent,
                _ => throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support removing a child (child type is '{child.GetType().FullName}').")
            };

            ShellSectionControl.Items.Remove(contentToRemove);
        }
Пример #7
0
        public virtual void AddChild(MC.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            MC.ShellContent contentToAdd = child switch
            {
                MC.TemplatedPage childAsTemplatedPage => childAsTemplatedPage,  // Implicit conversion
                            MC.ShellContent childAsShellContent => childAsShellContent,
                            _ => throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support adding a child (child type is '{child.GetType().FullName}').")
            };

            // Ensure that there is non-null Content to avoid exceptions in Xamarin.Forms
            contentToAdd.Content ??= new MC.Page();

            if (ShellSectionControl.Items.Count >= physicalSiblingIndex)
            {
                ShellSectionControl.Items.Insert(physicalSiblingIndex, contentToAdd);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but ShellSectionControl.Items.Count={ShellSectionControl.Items.Count}");
                ShellSectionControl.Items.Add(contentToAdd);
            }
        }
Пример #8
0
 private void Register()
 {
     if (TargetElement == null)
     {
         return;
     }
     if (EnableListenSource)
     {
         dpd = DependencyPropertyDescriptor.FromProperty(ListBox.ItemsSourceProperty, TargetElement.GetType());
         dpd.RemoveValueChanged(TargetElement, dpdValueChanged);
     }
     TargetElement.Loaded   += new RoutedEventHandler(TargetElement_Loaded);
     TargetElement.Unloaded += new RoutedEventHandler(TargetElement_Unloaded);
 }