- This enables changes to display after initial load
- Use native control attribute setters instead of always using Reflection
This commit is contained in:
Eilon Lipton 2019-08-12 11:03:29 -07:00
Родитель aa14c286a5
Коммит fba7eb8d7f
7 изменённых файлов: 40 добавлений и 32 удалений

Просмотреть файл

@ -65,8 +65,9 @@ namespace BlinForms.Framework
private void ApplySetAttribute(int siblingIndex, ref RenderTreeFrame attributeFrame)
{
//var target = (IBlazorNativeControl)Controls[siblingIndex];
//target.ApplyAttribute(ref attributeFrame);
// TODO: What to do with siblingIndex here?
var mapper = GetControlPropertyMapper(TargetControl);
mapper.SetControlProperty(attributeFrame.AttributeEventHandlerId, attributeFrame.AttributeName, attributeFrame.AttributeValue, attributeFrame.AttributeEventUpdatesAttributeName);
}
private void ApplyPrependFrame(int siblingIndex, RenderTreeFrame[] frames, int frameIndex)
@ -136,9 +137,8 @@ namespace BlinForms.Framework
foreach (var attribute in AttributeUtil.ElementAttributeFrames(frames, frameIndex))
{
// TODO: Do smarter property setting...? Not calling <NativeControl>.ApplyAttribute(...) right now. Should it?
var attributeCopy = attribute;
var mapper = GetControlPropertyMapper(nativeControl);
mapper.SetControlProperty(attributeCopy.AttributeEventHandlerId, attributeCopy.AttributeName, attributeCopy.AttributeValue, attributeCopy.AttributeEventUpdatesAttributeName);
mapper.SetControlProperty(attribute.AttributeEventHandlerId, attribute.AttributeName, attribute.AttributeValue, attribute.AttributeEventUpdatesAttributeName);
}
return nativeControl;

Просмотреть файл

@ -34,18 +34,18 @@ namespace BlinForms.Framework.Controls
};
}
public void ApplyAttribute(ref RenderTreeFrame attribute)
public void ApplyAttribute(ulong attributeEventHandlerId, string attributeName, object attributeValue, string attributeEventUpdatesAttributeName)
{
switch (attribute.AttributeName)
switch (attributeName)
{
case nameof(Text):
Text = (string)attribute.AttributeValue;
Text = (string)attributeValue;
break;
case "onclick":
ClickEventHandlerId = attribute.AttributeEventHandlerId;
ClickEventHandlerId = attributeEventHandlerId;
break;
default:
FormsComponentBase.ApplyAttribute(this, ref attribute);
FormsComponentBase.ApplyAttribute(this, attributeEventHandlerId, attributeName, attributeValue, attributeEventUpdatesAttributeName);
break;
}
}

Просмотреть файл

@ -30,29 +30,29 @@ namespace BlinForms.Framework.Controls
{
}
public static void ApplyAttribute(Control control, ref RenderTreeFrame attributeFrame)
public static void ApplyAttribute(Control control, ulong attributeEventHandlerId, string attributeName, object attributeValue, string attributeEventUpdatesAttributeName)
{
switch (attributeFrame.AttributeName)
switch (attributeName)
{
// TODO: Fix not setting default values for types. Maybe use nullable types on components?
case nameof(Top):
if ((attributeFrame.AttributeValue as string) != "0")
control.Top = int.Parse((string)attributeFrame.AttributeValue);
if ((attributeValue as string) != "0")
control.Top = int.Parse((string)attributeValue);
break;
case nameof(Left):
if ((attributeFrame.AttributeValue as string) != "0")
control.Left = int.Parse((string)attributeFrame.AttributeValue);
if ((attributeValue as string) != "0")
control.Left = int.Parse((string)attributeValue);
break;
case nameof(Width):
if ((attributeFrame.AttributeValue as string) != "0")
control.Width = int.Parse((string)attributeFrame.AttributeValue);
if ((attributeValue as string) != "0")
control.Width = int.Parse((string)attributeValue);
break;
case nameof(Height):
if ((attributeFrame.AttributeValue as string) != "0")
control.Height = int.Parse((string)attributeFrame.AttributeValue);
if ((attributeValue as string) != "0")
control.Height = int.Parse((string)attributeValue);
break;
default:
throw new NotImplementedException($"FormsComponentBase doesn't recognize attribute '{attributeFrame.AttributeName}'");
throw new NotImplementedException($"FormsComponentBase doesn't recognize attribute '{attributeName}'");
}
}
}

Просмотреть файл

@ -4,6 +4,6 @@ namespace BlinForms.Framework.Controls
{
internal interface IBlazorNativeControl
{
void ApplyAttribute(ref RenderTreeFrame attribute);
void ApplyAttribute(ulong attributeEventHandlerId, string attributeName, object attributeValue, string attributeEventUpdatesAttributeName);
}
}

Просмотреть файл

@ -23,15 +23,15 @@ namespace BlinForms.Framework.Controls
{
}
public void ApplyAttribute(ref RenderTreeFrame attribute)
public void ApplyAttribute(ulong attributeEventHandlerId, string attributeName, object attributeValue, string attributeEventUpdatesAttributeName)
{
switch (attribute.AttributeName)
switch (attributeName)
{
case nameof(Text):
Text = (string)attribute.AttributeValue;
Text = (string)attributeValue;
break;
default:
FormsComponentBase.ApplyAttribute(this, ref attribute);
FormsComponentBase.ApplyAttribute(this, attributeEventHandlerId, attributeName, attributeValue, attributeEventUpdatesAttributeName);
break;
}
}

Просмотреть файл

@ -32,21 +32,21 @@ namespace BlinForms.Framework.Controls
{
}
public void ApplyAttribute(ref RenderTreeFrame attribute)
public void ApplyAttribute(ulong attributeEventHandlerId, string attributeName, object attributeValue, string attributeEventUpdatesAttributeName)
{
switch (attribute.AttributeName)
switch (attributeName)
{
case nameof(Visible):
Visible = (bool)attribute.AttributeValue;
Visible = (bool)attributeValue;
break;
case nameof(BackColor):
BackColor = Color.FromArgb(argb: (int)attribute.AttributeValue);
BackColor = Color.FromArgb(argb: int.Parse((string)attributeValue));
break;
//case "onclick":
// ClickEventHandlerId = attribute.AttributeEventHandlerId;
// ClickEventHandlerId = attributeEventHandlerId;
// break;
default:
FormsComponentBase.ApplyAttribute(this, ref attribute);
FormsComponentBase.ApplyAttribute(this, attributeEventHandlerId, attributeName, attributeValue, attributeEventUpdatesAttributeName);
break;
}
}

Просмотреть файл

@ -1,4 +1,5 @@
using System.Diagnostics;
using BlinForms.Framework.Controls;
using System.Diagnostics;
using System.Windows.Forms;
namespace BlinForms.Framework
@ -14,6 +15,13 @@ namespace BlinForms.Framework
public void SetControlProperty(ulong attributeEventHandlerId, string attributeName, object attributeValue, string attributeEventUpdatesAttributeName)
{
if (_control is IBlazorNativeControl nativeControl)
{
// TODO: Does this need to return a 'bool' so we know if it actually set the property?
nativeControl.ApplyAttribute(attributeEventHandlerId, attributeName, attributeValue, attributeEventUpdatesAttributeName);
return;
}
// TODO: Figure out how to wire up events, e.g. OnClick
var propertyInfo = _control.GetType().GetProperty(attributeName);
if (propertyInfo != null)