Merge pull request #115 from irihitech/issue/53

fix: fix #53.
This commit is contained in:
Zhang Dian
2024-02-26 14:59:45 +08:00
committed by GitHub
7 changed files with 50 additions and 26 deletions

View File

@@ -4,14 +4,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="clr-namespace:Ursa.Demo.Pages"
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:DesignWidth="800"
mc:Ignorable="d">
<Design.DataContext>
<pages:IPv4DemoViewMode />
</Design.DataContext>
<StackPanel HorizontalAlignment="Left">
<ToggleButton
Name="format"
@@ -38,6 +37,6 @@
IPAddress="{Binding Address}"
ShowLeadingZero="{Binding #format.IsChecked}" />
<TextBlock Classes="" Text="Disabled" />
<u:IPv4Box Width="200" IsEnabled="False" />
<u:IPv4Box Width="200" IsEnabled="False" IPAddress="{Binding Address}" />
</StackPanel>
</UserControl>

View File

@@ -12,18 +12,5 @@ public partial class IPv4BoxDemo : UserControl
public IPv4BoxDemo()
{
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);
}
}

View File

@@ -13,6 +13,10 @@
<SolidColorBrush x:Key="MaskBorder" Color="Red" />
</UserControl.Resources>
<StackPanel>
<u:Banner
Content="Setting the Scale before loading has no effect."
Header="Notice"
Type="Warning" />
<u:ImageViewer
Name="viewer"
Width="600"

View File

@@ -1,6 +1,20 @@
using System;
using System.Net;
using CommunityToolkit.Mvvm.ComponentModel;
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);
}
}

View File

@@ -121,7 +121,8 @@
<Setter Property="Border.BorderBrush" Value="{DynamicResource IPv4BoxFocusBorderBrush}" />
</Style>
<Style Selector="^:disabled">
<Setter Property="Border.Background" Value="{DynamicResource IPv4BoxDisabledBackground}" />
<Setter Property="Background" Value="{DynamicResource IPv4BoxDisabledBackground}" />
<Setter Property="Foreground" Value="{DynamicResource SemiColorDisabledText}" />
</Style>
</ControlTheme>
</ResourceDictionary>

View File

@@ -115,6 +115,19 @@ public class IPv4Box: TemplatedControl
_presenters[1] = _secondText;
_presenters[2] = _thirdText;
_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)

View File

@@ -3,6 +3,7 @@ using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Media.Imaging;
@@ -149,6 +150,7 @@ public class ImageViewer: TemplatedControl
private void OnSourceChanged(AvaloniaPropertyChangedEventArgs args)
{
if(!IsLoaded) return;
IImage image = args.GetNewValue<IImage>();
Size size = image.Size;
double width = this.Bounds.Width;
@@ -184,7 +186,16 @@ public class ImageViewer: TemplatedControl
base.OnApplyTemplate(e);
_image = e.NameScope.Get<Image>(PART_Image);
_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;
double width = Bounds.Width;
@@ -193,14 +204,9 @@ public class ImageViewer: TemplatedControl
_image.Height = size.Height;
Scale = GetScaleRatio(width/size.Width, height/size.Height, this.Stretch);
}
if (Overlayer is { } c)
{
AdornerLayer.SetAdorner(this, c);
}
}
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
base.OnPointerWheelChanged(e);