/// <summary> /// Creates a component of type <paramref name="componentType"/> and adds it as a child of <paramref name="parent"/>. If parameters are provided they will be set on the component. /// </summary> /// <param name="componentType"></param> /// <param name="parent"></param> /// <param name="parameters"></param> /// <returns></returns> public async Task <IComponent> AddComponent(Type componentType, IElementHandler parent, Dictionary <string, object> parameters = null) { try { return(await Dispatcher.InvokeAsync(async() => { var component = InstantiateComponent(componentType); var componentId = AssignRootComponentId(component); var rootAdapter = new NativeComponentAdapter(this, closestPhysicalParent: parent, knownTargetElement: parent) { Name = $"RootAdapter attached to {parent.GetType().FullName}", }; _componentIdToAdapter[componentId] = rootAdapter; SetParameterArguments(component, parameters); await RenderRootComponentAsync(componentId).ConfigureAwait(false); return component; }).ConfigureAwait(false)); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) #pragma warning restore CA1031 // Do not catch general exception types { HandleException(ex); return(null); } }
/// <summary> /// Creates a component of type <paramref name="componentType"/> and adds it as a child of <paramref name="parent"/>. /// </summary> /// <param name="componentType"></param> /// <param name="parent"></param> /// <returns></returns> public async Task AddComponent(Type componentType, IElementHandler parent) { await Dispatcher.InvokeAsync(async() => { var component = InstantiateComponent(componentType); var componentId = AssignRootComponentId(component); var rootAdapter = new NativeComponentAdapter(this, closestPhysicalParent: parent, knownTargetElement: parent) { Name = $"RootAdapter attached to {parent.GetType().FullName}", }; _componentIdToAdapter[componentId] = rootAdapter; await RenderRootComponentAsync(componentId).ConfigureAwait(false); }).ConfigureAwait(false); }
/// <summary> /// Creates a component of type <paramref name="componentType"/> and adds it as a child of <paramref name="parent"/>. If parameters are provided they will be set on the component. /// </summary> /// <param name="componentType"></param> /// <param name="parent"></param> /// <param name="parameters"></param> /// <returns></returns> public async Task <IComponent> AddComponent(Type componentType, IElementHandler parent, Dictionary <string, string> parameters = null) { return(await Dispatcher.InvokeAsync(async() => { var component = InstantiateComponent(componentType); var componentId = AssignRootComponentId(component); var rootAdapter = new NativeComponentAdapter(this, closestPhysicalParent: parent, knownTargetElement: parent) { Name = $"RootAdapter attached to {parent.GetType().FullName}", }; _componentIdToAdapter[componentId] = rootAdapter; SetNavigationParameters(component, parameters); await RenderRootComponentAsync(componentId).ConfigureAwait(false); return component; }).ConfigureAwait(false)); }
/// <summary> /// Creates a component of type <paramref name="componentType"/> and adds it as a child /// of <paramref name="parent"/>. /// </summary> /// <param name="componentType">The type of component to create.</param> /// <param name="parent">The parent to add the component to.</param> /// <param name="initialParameters">The <see cref="ParameterView"/> with the initial parameters.</param> /// <returns>A tuple of (<see cref="int"/> ComponentId, <see cref="IComponent"/> Component).</returns> protected async Task <(int ComponentId, IComponent Component)> AddComponent(Type componentType, IElementHandler parent, ParameterView initialParameters) { var result = await Dispatcher.InvokeAsync(() => { var component = InstantiateComponent(componentType); var componentId = AssignRootComponentId(component); var rootAdapter = new NativeComponentAdapter(this, closestPhysicalParent: parent, knownTargetElement: parent) { Name = $"RootAdapter attached to {parent.GetType().FullName}", }; _componentIdToAdapter[componentId] = rootAdapter; return(componentId, component); }).ConfigureAwait(false); await RenderRootComponentAsync(result.componentId, initialParameters).ConfigureAwait(false); return(result); }