feat: update demo
This commit is contained in:
@@ -90,6 +90,7 @@ public class IPv4Box: TemplatedControl
|
||||
static IPv4Box()
|
||||
{
|
||||
ShowLeadingZeroProperty.Changed.AddClassHandler<IPv4Box>((o, e) => o.OnFormatChange(e));
|
||||
IPAddressProperty.Changed.AddClassHandler<IPv4Box>((o, e) => o.OnIPChanged(e));
|
||||
}
|
||||
|
||||
private void OnFormatChange(AvaloniaPropertyChangedEventArgs arg)
|
||||
@@ -98,6 +99,32 @@ public class IPv4Box: TemplatedControl
|
||||
ParseBytes(showLeadingZero);
|
||||
}
|
||||
|
||||
private void OnIPChanged(AvaloniaPropertyChangedEventArgs arg)
|
||||
{
|
||||
IPAddress? address = arg.GetNewValue<IPAddress?>();
|
||||
if (address is null)
|
||||
{
|
||||
foreach (var presenter in _presenters)
|
||||
{
|
||||
if(presenter!=null) presenter.Text = string.Empty;
|
||||
}
|
||||
ParseBytes(ShowLeadingZero);
|
||||
}
|
||||
else
|
||||
{
|
||||
var sections = address.ToString().Split('.');
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
var presenter = _presenters[i];
|
||||
if (presenter != null)
|
||||
{
|
||||
presenter.Text = sections[i];
|
||||
}
|
||||
}
|
||||
ParseBytes(ShowLeadingZero);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
|
||||
Reference in New Issue
Block a user