fix: fix #53.
This commit is contained in:
@@ -4,14 +4,13 @@
|
|||||||
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"
|
||||||
|
xmlns:vm="clr-namespace:Ursa.Demo.ViewModels;assembly=Ursa.Demo"
|
||||||
|
x:DataType="vm:IPv4BoxDemoViewModel"
|
||||||
|
x:CompileBindings="True"
|
||||||
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">
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
Name="format"
|
Name="format"
|
||||||
@@ -38,6 +37,6 @@
|
|||||||
IPAddress="{Binding Address}"
|
IPAddress="{Binding Address}"
|
||||||
ShowLeadingZero="{Binding #format.IsChecked}" />
|
ShowLeadingZero="{Binding #format.IsChecked}" />
|
||||||
<TextBlock Classes="" Text="Disabled" />
|
<TextBlock Classes="" Text="Disabled" />
|
||||||
<u:IPv4Box Width="200" IsEnabled="False" />
|
<u:IPv4Box Width="200" IsEnabled="False" IPAddress="{Binding Address}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -12,18 +12,5 @@ public partial class IPv4BoxDemo : UserControl
|
|||||||
public IPv4BoxDemo()
|
public IPv4BoxDemo()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = new IPv4DemoViewMode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public partial class IPv4DemoViewMode: ObservableObject
|
|
||||||
{
|
|
||||||
[ObservableProperty]
|
|
||||||
private IPAddress? _address;
|
|
||||||
|
|
||||||
public void ChangeAddress()
|
|
||||||
{
|
|
||||||
long l = Random.Shared.NextInt64(0x00000000FFFFFFFF);
|
|
||||||
Address = new IPAddress(l);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,10 @@
|
|||||||
<SolidColorBrush x:Key="MaskBorder" Color="Red" />
|
<SolidColorBrush x:Key="MaskBorder" Color="Red" />
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
|
<u:Banner
|
||||||
|
Content="Setting the Scale before loading has no effect."
|
||||||
|
Header="Notice"
|
||||||
|
Type="Warning" />
|
||||||
<u:ImageViewer
|
<u:ImageViewer
|
||||||
Name="viewer"
|
Name="viewer"
|
||||||
Width="600"
|
Width="600"
|
||||||
|
|||||||
@@ -1,6 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
namespace Ursa.Demo.ViewModels;
|
namespace Ursa.Demo.ViewModels;
|
||||||
|
|
||||||
public class IPv4BoxDemoViewModel: ViewModelBase
|
public partial class IPv4BoxDemoViewModel: ObservableObject
|
||||||
{
|
{
|
||||||
|
[ObservableProperty] private IPAddress? _address;
|
||||||
|
|
||||||
|
public IPv4BoxDemoViewModel()
|
||||||
|
{
|
||||||
|
Address = IPAddress.Parse("192.168.1.1");
|
||||||
|
}
|
||||||
|
public void ChangeAddress()
|
||||||
|
{
|
||||||
|
long l = Random.Shared.NextInt64(0x00000000FFFFFFFF);
|
||||||
|
Address = new IPAddress(l);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,8 @@
|
|||||||
<Setter Property="Border.BorderBrush" Value="{DynamicResource IPv4BoxFocusBorderBrush}" />
|
<Setter Property="Border.BorderBrush" Value="{DynamicResource IPv4BoxFocusBorderBrush}" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style Selector="^:disabled">
|
<Style Selector="^:disabled">
|
||||||
<Setter Property="Border.Background" Value="{DynamicResource IPv4BoxDisabledBackground}" />
|
<Setter Property="Background" Value="{DynamicResource IPv4BoxDisabledBackground}" />
|
||||||
|
<Setter Property="Foreground" Value="{DynamicResource SemiColorDisabledText}" />
|
||||||
</Style>
|
</Style>
|
||||||
</ControlTheme>
|
</ControlTheme>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
|
|||||||
@@ -115,6 +115,19 @@ public class IPv4Box: TemplatedControl
|
|||||||
_presenters[1] = _secondText;
|
_presenters[1] = _secondText;
|
||||||
_presenters[2] = _thirdText;
|
_presenters[2] = _thirdText;
|
||||||
_presenters[3] = _fourthText;
|
_presenters[3] = _fourthText;
|
||||||
|
if (this.IPAddress != null)
|
||||||
|
{
|
||||||
|
var sections = IPAddress.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 OnKeyDown(KeyEventArgs e)
|
protected override void OnKeyDown(KeyEventArgs e)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Avalonia.Controls;
|
|||||||
using Avalonia.Controls.Metadata;
|
using Avalonia.Controls.Metadata;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using Avalonia.Media.Imaging;
|
using Avalonia.Media.Imaging;
|
||||||
|
|
||||||
@@ -149,6 +150,7 @@ public class ImageViewer: TemplatedControl
|
|||||||
|
|
||||||
private void OnSourceChanged(AvaloniaPropertyChangedEventArgs args)
|
private void OnSourceChanged(AvaloniaPropertyChangedEventArgs args)
|
||||||
{
|
{
|
||||||
|
if(!IsLoaded) return;
|
||||||
IImage image = args.GetNewValue<IImage>();
|
IImage image = args.GetNewValue<IImage>();
|
||||||
Size size = image.Size;
|
Size size = image.Size;
|
||||||
double width = this.Bounds.Width;
|
double width = this.Bounds.Width;
|
||||||
@@ -184,7 +186,16 @@ public class ImageViewer: TemplatedControl
|
|||||||
base.OnApplyTemplate(e);
|
base.OnApplyTemplate(e);
|
||||||
_image = e.NameScope.Get<Image>(PART_Image);
|
_image = e.NameScope.Get<Image>(PART_Image);
|
||||||
_layer = e.NameScope.Get<VisualLayerManager>(PART_Layer);
|
_layer = e.NameScope.Get<VisualLayerManager>(PART_Layer);
|
||||||
if (Source is { } i)
|
if (Overlayer is { } c)
|
||||||
|
{
|
||||||
|
AdornerLayer.SetAdorner(this, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnLoaded(RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnLoaded(e);
|
||||||
|
if (Source is { } i && _image is { })
|
||||||
{
|
{
|
||||||
Size size = i.Size;
|
Size size = i.Size;
|
||||||
double width = Bounds.Width;
|
double width = Bounds.Width;
|
||||||
@@ -193,14 +204,9 @@ public class ImageViewer: TemplatedControl
|
|||||||
_image.Height = size.Height;
|
_image.Height = size.Height;
|
||||||
Scale = GetScaleRatio(width/size.Width, height/size.Height, this.Stretch);
|
Scale = GetScaleRatio(width/size.Width, height/size.Height, this.Stretch);
|
||||||
}
|
}
|
||||||
if (Overlayer is { } c)
|
|
||||||
{
|
|
||||||
AdornerLayer.SetAdorner(this, c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
|
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnPointerWheelChanged(e);
|
base.OnPointerWheelChanged(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user