.NET WinForms to WPF

Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.

Moderator: Alex

Post Reply
marco.groppelli
Posts: 9
Joined: Mon Mar 13, 2023 11:19 am

.NET WinForms to WPF

Post by marco.groppelli »

Good morning,

We implemented a .NET 4.8 WinForms application with VintaSoft v12.4, using the Annotation plugin with a customized image viewer that includes user interactions such as ROI selection, zoom, pan, image rulers, etc.

The references in the project are:
Imaging
Imaging.Annotation.UI
Imaging.Gdi
Imaging.UI
Imaging.Shared

Now we have to convert the WinForms project to a WPF project.
What is the easiest way to do it? Is there a correspondence between the WinForms and WPF VintaSoft assembly versions?"
Alex
Site Admin
Posts: 2393
Joined: Thu Jul 10, 2008 2:21 pm

Re: .NET WinForms to WPF

Post by Alex »

Hello Marko,

For solving your task you need to change AnnotationViewer control to the WpfAnnotationViewer control, PanTool to the WpfPanTool, etc.

WinForms and WPF controls and classes have identical architecture if functionality does not depend from platform related functionality.

Please try to convert your WinForms application to WPF application and let us know if you will have any problem.

Best regards, Alexander
marco.groppelli
Posts: 9
Joined: Mon Mar 13, 2023 11:19 am

Re: .NET WinForms to WPF

Post by marco.groppelli »

Hello Alex,

Thanks for your reply. We have seen that the rules for adding "Wpf" in front are pretty much okay, but we can't find these ones for Wpf:
- Imaging.UI.ImageViewer.PointToImage
- Imaging.UI.ImageViewer.ClientRectangle
- Imaging.UI.ImageViewer.ScrollToPoint

Please, can you tell us the equivalent for WPF?

Probably, we are using something more, but let's start with these.
Alex
Site Admin
Posts: 2393
Joined: Thu Jul 10, 2008 2:21 pm

Re: .NET WinForms to WPF

Post by Alex »

Hello Marco,

If you need WPF equivalent for ImageViewer.PointToImage method, please use the WpfImageViewer.PointFromControlToImage method.

If you need WPF equivalent for ImageViewer.ClientRectangle property, please use the WpfImageViewer.ActualWidth and WpfImageViewer.ActualHeight properties.

If you need WPF equivalent for ImageViewer.ScrollToPoint method, please use the WpfImageViewer.ScrollToPoint method.

Also please read about properties and methods of Vintasoft.Imaging.Wpf.UI.WpfImageViewer class in documentation: https://www.vintasoft.com/docs/vsimagin ... iewer.html

Best regards, Alexander
marco.groppelli
Posts: 9
Joined: Mon Mar 13, 2023 11:19 am

Re: .NET WinForms to WPF

Post by marco.groppelli »

Hello Alex,

Regarding the property Imaging.UI.ImageViewer.ClientRectangle being substituted by WpfImageViewer.ActualWidth/ActualHeight, we have noticed they behave differently.

In WinForms, the scrollbars are outside the annotationViewer and are not included in the ClientRectangle. In WPF, however, the scrollbars are inside the annotationViewer and are included in WpfImageViewer.ActualWidth/ActualHeight.

Is there a correct way to determine if each scrollbar is visible?
We tried using WpfImageViewerState.AutoScrollSize, but sometimes, when using the "BestFit" zoom value, the AutoScrollSize remains 0 even if the scrollbar is visible.
Alex
Site Admin
Posts: 2393
Joined: Thu Jul 10, 2008 2:21 pm

Re: .NET WinForms to WPF

Post by Alex »

Hello Marco,

Here is equivalent of ImageViewer.ClientRectangle method for WpfImageViewer:

Code: Select all

public static Size GetClientSize(WpfImageViewer viewer)
{
    double w = viewer.ActualWidth;
    double h = viewer.ActualHeight;

    if (viewer.ComputedHorizontalScrollBarVisibility == Visibility.Visible)
        w -= SystemParameters.VerticalScrollBarWidth;
    if (viewer.ComputedVerticalScrollBarVisibility == Visibility.Visible)
        h -= SystemParameters.HorizontalScrollBarHeight;

    return new Size(Math.Max(0, w), Math.Max(0, h));
}
Best regards, Alexander
marco.groppelli
Posts: 9
Joined: Mon Mar 13, 2023 11:19 am

Re: .NET WinForms to WPF

Post by marco.groppelli »

Hi Alex,

Thank you for your previous responses: they’ve all worked, and I really appreciate your help. However, the transition from WinForms to WPF is proving to be more complicated than I expected.

I’m currently having issues with the utility that maintains the scroll position when a new image is loaded, which is also used to transfer the view state from one WpfImageViewer to another.

In WinForms, it was sufficient to restore the desired AutoScrollPositionEx property in the ImagePaint event.
However, in WPF, I’m running into several challenges. The first issue is that ImagePaint doesn’t always occur. I’ve tried using the ScrollChanged and AutoScrollPositionExChanged events, but they aren’t triggering as expected. For instance, AutoScrollPositionExChanged occurs even when a new image is loaded, which isn't ideal.

What would you suggest in this case?

Thanks in advance for your help.
Alex
Site Admin
Posts: 2393
Joined: Thu Jul 10, 2008 2:21 pm

Re: .NET WinForms to WPF

Post by Alex »

Hi Marco,

For understanding the problem we need to reproduce the problem on our side. Could you send us (to support@vintasoft.com) a small project that demonstrates the problem?

Best regards, Alexander
Post Reply