feat: update demo
This commit is contained in:
@@ -4,14 +4,32 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:pages="clr-namespace:Ursa.Demo.Pages"
|
||||||
xmlns:u="https://irihi.tech/ursa"
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
<Design.DataContext>
|
||||||
|
<pages:IPv4DemoViewMode />
|
||||||
|
</Design.DataContext>
|
||||||
<StackPanel HorizontalAlignment="Left">
|
<StackPanel HorizontalAlignment="Left">
|
||||||
<u:IPv4Box Name="box" Width="200" />
|
<ToggleButton
|
||||||
<u:IPv4Box Width="200" IsEnabled="False" />
|
Name="format"
|
||||||
|
Margin="0,0,0,50"
|
||||||
|
Content="Show Leading Zeroes" />
|
||||||
|
|
||||||
|
<u:IPv4Box
|
||||||
|
Name="box"
|
||||||
|
Width="200"
|
||||||
|
ShowLeadingZero="{Binding #format.IsChecked}" />
|
||||||
<TextBlock Text="IP: " />
|
<TextBlock Text="IP: " />
|
||||||
<TextBlock Text="{Binding #box.IPAddress}" />
|
<TextBlock Text="{Binding #box.IPAddress}" />
|
||||||
|
|
||||||
|
<RepeatButton Command="{Binding ChangeAddress}" Content="Random" />
|
||||||
|
<u:IPv4Box
|
||||||
|
Width="200"
|
||||||
|
IPAddress="{Binding Address}"
|
||||||
|
ShowLeadingZero="{Binding #format.IsChecked}" />
|
||||||
|
<u:IPv4Box Width="200" IsEnabled="False" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace Ursa.Demo.Pages;
|
namespace Ursa.Demo.Pages;
|
||||||
|
|
||||||
@@ -9,10 +12,18 @@ public partial class IPv4BoxDemo : UserControl
|
|||||||
public IPv4BoxDemo()
|
public IPv4BoxDemo()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
DataContext = new IPv4DemoViewMode();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void InitializeComponent()
|
public partial class IPv4DemoViewMode: ObservableObject
|
||||||
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private IPAddress? _address;
|
||||||
|
|
||||||
|
public void ChangeAddress()
|
||||||
{
|
{
|
||||||
AvaloniaXamlLoader.Load(this);
|
long l = Random.Shared.NextInt64(0x00000000FFFFFFFF);
|
||||||
|
Address = new IPAddress(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +90,7 @@ public class IPv4Box: TemplatedControl
|
|||||||
static IPv4Box()
|
static IPv4Box()
|
||||||
{
|
{
|
||||||
ShowLeadingZeroProperty.Changed.AddClassHandler<IPv4Box>((o, e) => o.OnFormatChange(e));
|
ShowLeadingZeroProperty.Changed.AddClassHandler<IPv4Box>((o, e) => o.OnFormatChange(e));
|
||||||
|
IPAddressProperty.Changed.AddClassHandler<IPv4Box>((o, e) => o.OnIPChanged(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFormatChange(AvaloniaPropertyChangedEventArgs arg)
|
private void OnFormatChange(AvaloniaPropertyChangedEventArgs arg)
|
||||||
@@ -98,6 +99,32 @@ public class IPv4Box: TemplatedControl
|
|||||||
ParseBytes(showLeadingZero);
|
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)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate(e);
|
base.OnApplyTemplate(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user