Define NativeControlComponentBase so as to eliminate direct use of RenderTreeBuilder in consumers
This commit is contained in:
Родитель
d1bc4a6700
Коммит
b4f31e48a4
|
@ -16,10 +16,13 @@ namespace BlinForms.Framework.Controls
|
|||
|
||||
protected override void RenderAttributes(AttributesBuilder builder)
|
||||
{
|
||||
base.RenderAttributes(builder);
|
||||
|
||||
if (Text != null)
|
||||
{
|
||||
builder.AddAttribute(nameof(Text), Text);
|
||||
}
|
||||
|
||||
builder.AddAttribute("onclick", OnClick);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Emblazon;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.RenderTree;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
@ -6,7 +7,7 @@ using System.Windows.Forms;
|
|||
|
||||
namespace BlinForms.Framework.Controls
|
||||
{
|
||||
public abstract class FormsComponentBase : ComponentBase
|
||||
public abstract class FormsComponentBase : NativeControlComponentBase
|
||||
{
|
||||
[Parameter] public int? Top { get; set; }
|
||||
[Parameter] public int? Left { get; set; }
|
||||
|
@ -20,60 +21,40 @@ namespace BlinForms.Framework.Controls
|
|||
|
||||
[Parameter] public AnchorStyles? Anchor { get; set; }
|
||||
|
||||
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
||||
protected override void RenderAttributes(AttributesBuilder builder)
|
||||
{
|
||||
builder.OpenElement(0, GetType().FullName);
|
||||
|
||||
RenderAttributes(new AttributesBuilder(builder));
|
||||
|
||||
if (Top != null)
|
||||
{
|
||||
builder.AddAttribute(100, nameof(Top), Top.Value);
|
||||
builder.AddAttribute(nameof(Top), Top.Value);
|
||||
}
|
||||
if (Left != null)
|
||||
{
|
||||
builder.AddAttribute(101, nameof(Left), Left.Value);
|
||||
builder.AddAttribute(nameof(Left), Left.Value);
|
||||
}
|
||||
if (Width != null)
|
||||
{
|
||||
builder.AddAttribute(102, nameof(Width), Width.Value);
|
||||
builder.AddAttribute(nameof(Width), Width.Value);
|
||||
}
|
||||
if (Height != null)
|
||||
{
|
||||
builder.AddAttribute(103, nameof(Height), Height.Value);
|
||||
builder.AddAttribute(nameof(Height), Height.Value);
|
||||
}
|
||||
if (Visible != null)
|
||||
{
|
||||
builder.AddAttribute(104, nameof(Visible), Visible.Value);
|
||||
builder.AddAttribute(nameof(Visible), Visible.Value);
|
||||
}
|
||||
if (BackColor != null)
|
||||
{
|
||||
builder.AddAttribute(105, nameof(BackColor), BackColor.Value.ToArgb());
|
||||
builder.AddAttribute(nameof(BackColor), BackColor.Value.ToArgb());
|
||||
}
|
||||
if (TabIndex != null)
|
||||
{
|
||||
builder.AddAttribute(106, nameof(TabIndex), TabIndex.Value);
|
||||
builder.AddAttribute(nameof(TabIndex), TabIndex.Value);
|
||||
}
|
||||
if (Anchor != null)
|
||||
{
|
||||
builder.AddAttribute(107, nameof(Anchor), (int)Anchor.Value);
|
||||
builder.AddAttribute(nameof(Anchor), (int)Anchor.Value);
|
||||
}
|
||||
|
||||
RenderContents(builder);
|
||||
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
||||
protected virtual void RenderAttributes(AttributesBuilder builder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rendered contents should use sequence values 1000+.
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
protected virtual void RenderContents(RenderTreeBuilder builder)
|
||||
{
|
||||
}
|
||||
|
||||
public static void ApplyAttribute(Control control, ulong attributeEventHandlerId, string attributeName, object attributeValue, string attributeEventUpdatesAttributeName)
|
||||
|
|
|
@ -15,6 +15,8 @@ namespace BlinForms.Framework.Controls
|
|||
|
||||
protected override void RenderAttributes(AttributesBuilder builder)
|
||||
{
|
||||
base.RenderAttributes(builder);
|
||||
|
||||
if (Text != null)
|
||||
{
|
||||
builder.AddAttribute(nameof(Text), Text);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using Emblazon;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.RenderTree;
|
||||
|
||||
namespace BlinForms.Framework.Controls
|
||||
{
|
||||
|
@ -13,10 +12,7 @@ namespace BlinForms.Framework.Controls
|
|||
|
||||
[Parameter] public RenderFragment ChildContent { get; set; }
|
||||
|
||||
protected override void RenderContents(RenderTreeBuilder builder)
|
||||
{
|
||||
builder.AddContent(1000, ChildContent);
|
||||
}
|
||||
protected override RenderFragment GetChildContent() => ChildContent;
|
||||
|
||||
class BlazorPanel : System.Windows.Forms.Panel, IBlazorNativeControl
|
||||
{
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using Emblazon;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.RenderTree;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace BlinForms.Framework.Controls
|
||||
|
@ -17,16 +16,15 @@ namespace BlinForms.Framework.Controls
|
|||
|
||||
protected override void RenderAttributes(AttributesBuilder builder)
|
||||
{
|
||||
base.RenderAttributes(builder);
|
||||
|
||||
if (Orientation != null)
|
||||
{
|
||||
builder.AddAttribute(nameof(Orientation), (int)Orientation.Value);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RenderContents(RenderTreeBuilder builder)
|
||||
{
|
||||
builder.AddContent(1000, ChildContent);
|
||||
}
|
||||
protected override RenderFragment GetChildContent() => ChildContent;
|
||||
|
||||
class BlazorSplitContainer : System.Windows.Forms.SplitContainer, IBlazorNativeControl
|
||||
{
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.RenderTree;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
@ -24,9 +23,6 @@ namespace BlinForms.Framework.Controls
|
|||
|
||||
[Parameter] public RenderFragment ChildContent { get; set; }
|
||||
|
||||
protected override void RenderContents(RenderTreeBuilder builder)
|
||||
{
|
||||
builder.AddContent(1000, ChildContent);
|
||||
}
|
||||
protected override RenderFragment GetChildContent() => ChildContent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ namespace BlinForms.Framework.Controls
|
|||
|
||||
protected override void RenderAttributes(AttributesBuilder builder)
|
||||
{
|
||||
base.RenderAttributes(builder);
|
||||
|
||||
if (Text != null)
|
||||
{
|
||||
builder.AddAttribute(nameof(Text), Text);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Microsoft.AspNetCore.Components.RenderTree;
|
||||
|
||||
namespace BlinForms.Framework.Controls
|
||||
namespace Emblazon
|
||||
{
|
||||
// This wraps a RenderTreeBuilder in such a way that consumers
|
||||
// can only call the desired AddAttribute method, can't supply
|
|
@ -0,0 +1,31 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.RenderTree;
|
||||
|
||||
namespace Emblazon
|
||||
{
|
||||
public abstract class NativeControlComponentBase : ComponentBase
|
||||
{
|
||||
protected override void BuildRenderTree(RenderTreeBuilder builder)
|
||||
{
|
||||
builder.OpenElement(0, GetType().FullName);
|
||||
RenderAttributes(new AttributesBuilder(builder));
|
||||
|
||||
var childContent = GetChildContent();
|
||||
if (childContent != null)
|
||||
{
|
||||
builder.AddContent(2, childContent);
|
||||
}
|
||||
|
||||
builder.CloseElement();
|
||||
}
|
||||
|
||||
protected virtual void RenderAttributes(AttributesBuilder builder)
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual RenderFragment GetChildContent()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче