public bool Add(XF.ShellContent view, int index, object child, IComponentAdapterController rootAdapter, bool @throw = true)
        {
            switch (child)
            {
            case ContentPage page:
                view.Content = page;
                break;

            case TemplatedPage tpage:
                view.Content = tpage;
                break;

            case XRF.DataTemplate template:
                view.ContentTemplate = template.P;
                break;

            default:
                if (@throw)
                {
                    throw new InvalidOperationException($"{view.GetType()} supports only ChildContent of type {typeof(XF.ContentPage)} or  {typeof(XF.TemplatedPage)}");
                }
                return(false);
            }
            return(true);
        }
コード例 #2
0
 public object Adapt(TComponentToXamarinBridge component, IComponentAdapterController rootAdapter)
 {
     if (component.Property != null) //return the component back so the setter can know which property to assign to
     {
         return(component);
     }
     return(component.Element);
 }
 public bool Add(XRF.DataTemplate template, int index, object child, IComponentAdapterController rootAdapter, bool @throw = true)
 {
     if (template.ChildContent == null && template.Template == null)
     {
         throw new InvalidOperationException($"{typeof(XF.DataTemplate)} must have either ChildContent or Type set");
     }
     if (child != null)
     {
         //since DataTemplate is constructed in razor, the default constructor was used and this has no child element.
         //We make a new template
         //Also since datatemplate needs to be repeated for each item, the element passed here is useless
         //we create a new element in the DataTemplate Action
         XF.DataTemplate newDataTemplate = null;
         //try and guess the best root element for the data template by pre-rendering it and checking the type of the root element
         //var root = Razor.Create<object>(rootAdapter.ServiceProvider, template.ChildContent).Result;
         //if (template.ChildContent != null)
         //{
         if (child is XRF.ViewCell viewCell)
         {
             newDataTemplate = new XF.DataTemplate(() =>
             {
                 return(new CaptureCurrentObjectForViewCell(rootAdapter.ServiceProvider, viewCell.ChildContent));
             });
         }
         else if (child is XF.Element element)
         {
             newDataTemplate = new XF.DataTemplate(() =>
             {
                 return(element);
             });
         }
         //}
         //var newDataTemplate = new XF.DataTemplate(() =>
         //{
         //    return Razor.Create<DataTemplateComponent, Element>(rootAdapter.ServiceProvider, (t) =>
         //    {
         //        t.ChildContent = view.ChildContent;
         //    }).Result;
         //});
         //now we need to replace the old template with the new template
         //we find the adpater that set the old template into its parent and we ask it ro replace it
         //find the parent first
         if (newDataTemplate != null)
         {
             rootAdapter.Parent.Replace(template, new XRF.DataTemplate(newDataTemplate)
             {
                 Property = template.Property
             }, @throw);
             return(true);
         }
     }
     if (@throw)
     {
         throw new InvalidOperationException($"{typeof(XF.DataTemplate)} doesn't supports ChildContent of type {child.GetType()}");
     }
     return(false);
 }
 //since we defer the call o childcontent of datatemplate to prevent passing null parameter to the user provided template,
 //we have to process the DaatTemplate here else exception "LoadTemplate should not be null"
 public object Adapt(DataTemplate component, IComponentAdapterController rootAdapter)
 {
     if (component.Template == null && component.ChildContent == null)
     {
         throw new InvalidOperationException("DataTemplate must have either a Type or a ChildContent");
     }
     XF.DataTemplate newDataTemplate = null;
     if (component is DataTemplateTBase tbase && tbase.TemplateChildContent != null)
     {
         newDataTemplate = new XF.DataTemplate(() =>
         {
             return(new CaptureCurrentObjectForDataTemplateAsContentView(rootAdapter.ServiceProvider, tbase.TemplateChildContent));
         });
     }
コード例 #5
0
        public bool Add(Shell view, int index, object child, IComponentAdapterController rootAdapter, bool @throw = true)
        {
            switch (child)
            {
            case ShellSection shellSection:
                view.Items.Add(shellSection);
                break;

            case ShellContent shellContent:
                view.Items.Add(shellContent);
                break;

            case TemplatedPage page:
                view.Items.Add(page);
                break;

            case MenuItem menuItem:
                view.Items.Add(menuItem);
                break;

            case ShellItem shellItem:
                view.Items.Add(shellItem);
                break;

            default:
                if (child is ComponentToXamarinBridge bridge && bridge.Property == nameof(Shell.FlyoutHeader))
                {
                    view.FlyoutHeader = bridge.Element;
                    break;
                }
                if (@throw)
                {
                    throw new InvalidOperationException($"{view.GetType()} does not supports only ChildContent of type {child?.GetType()}");
                }
                return(false);
            }
            return(true);
        }
 public object Adapt(StyleSheet sheet, IComponentAdapterController rootAdapter)
 {
     rootAdapter.VisualElement.ContinueWith(task =>
     {
         var _parentVisualElement = task.Result;
         // TODO: Add logic to ensure same resource isn't added multiple times
         if (sheet.Resource != null)
         {
             if (sheet.Assembly == null)
             {
                 throw new InvalidOperationException($"Specifying a '{nameof(sheet.Resource)}' property value '{sheet.Resource}' requires also specifying the '{nameof(sheet.Assembly)}' property to indicate the assembly containing the resource.");
             }
             var styleSheet = XF.StyleSheets.StyleSheet.FromResource(resourcePath: sheet.Resource, assembly: sheet.Assembly);
             _parentVisualElement.Resources.Add(styleSheet);
         }
         if (sheet.Text != null)
         {
             using var reader = new StringReader(sheet.Text);
             var styleSheet   = XF.StyleSheets.StyleSheet.FromReader(reader);
             _parentVisualElement.Resources.Add(styleSheet);
         }
     });
     return(null);
 }
 public bool Replace(ShellContent view, object child, object newChild, IComponentAdapterController rootAdapter, bool @throw = true)
 {
     return(Add(view, -1, newChild, rootAdapter, @throw));
 }
 public bool Remove(ShellContent view, object child, IComponentAdapterController rootAdapter, bool @throw = true)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
        public static object Adapt(this IComponentAdapter adapter, object component, IComponentAdapterController rootAdapter)
        {
            var method = adapter.GetType().GetMethod(nameof(IComponentAdapter <ComponentBase> .Adapt));

            return(method.Invoke(adapter, new object[] { component, rootAdapter }));
        }
コード例 #10
0
 public object Adapt(TComponentBase component, IComponentAdapterController rootAdapter)
 {
     return(new XF.ContentView());
 }
 public bool Replace(XRF.DataTemplate view, object child, object newChild, IComponentAdapterController rootAdapter, bool @throw = true)
 {
     throw new NotImplementedException();
 }
 public object Adapt(ViewCell component, IComponentAdapterController rootAdapter)
 {
     return(component);
 }