Merge pull request #521 from irihitech/image

fix: fix image binding to stretch initialization issue.
This commit is contained in:
Dong Bin
2024-12-26 18:13:58 +08:00
committed by GitHub
3 changed files with 25 additions and 2 deletions

View File

@@ -12,12 +12,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Ursa Unit Test
run: dotnet test ./tests/Test.Ursa
- name: Ursa Headless Test
run: dotnet test ./tests/HeadlessTest.Ursa
ubuntu:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
- name: Ursa Unit Test
run: dotnet test ./tests/Test.Ursa
- name: Ursa Headless Test
run: dotnet test ./tests/HeadlessTest.Ursa
run: dotnet test ./tests/HeadlessTest.Ursa

View File

@@ -163,8 +163,9 @@ public class ImageViewer: TemplatedControl
private void OnStretchChanged(AvaloniaPropertyChangedEventArgs args)
{
if (_image is null) return;
var stretch = args.GetNewValue<Stretch>();
Scale = GetScaleRatio(Width / _image!.Width, Height / _image!.Height, stretch);
Scale = GetScaleRatio(Width / _image.Width, Height / _image.Height, stretch);
_sourceMinScale = _image is not null ? Math.Min(Width * MinScale / _image.Width, Height * MinScale / _image.Height) : MinScale;
}

View File

@@ -0,0 +1,17 @@
using Avalonia.Controls;
using Avalonia.Media;
using Ursa.Controls;
namespace Test.Ursa.Controls.ImageViewerTests.Stretch_Initial_Value;
public class StretchValueTest
{
[Fact]
public void Stretch_Initial_Value_Does_Not_Crash()
{
ImageViewer iv = new ImageViewer()
{
Stretch = Stretch.UniformToFill
};
}
}