xceedsoftware / wpftoolkit

All the controls missing in WPF. Over 1 million downloads.
Other
3.89k stars 877 forks source link

Zoombox complains with exception about negative values in 3.2.0 #1217

Open Anton-V-K opened 7 years ago

Anton-V-K commented 7 years ago

I've been using Zoombox with 3.1.0 without any issues. After upgrading to 3.2.0 the exception occurs saying about some negative values used for rect initialization. After manual downgrade to 3.1.0 the issue is gone...

The XAML fragment:

<UserControl ... >

<Grid>

    <xctk:Zoombox IsUsingScrollBars="True" KeepContentInBounds="True">

      <Canvas Name="canvasMain"
              Width="{Binding Project.Image.Width}" Height="{Binding Project.Image.Height}"
              >
   ...
      </Canvas>

    </xctk:Zoombox>
  </Grid>
</UserControl>

Probably something goes wrong when Canvas size is updated based on the bindings...

XceedBoucherS commented 7 years ago

Hi, I cannot reproduce the exception. Here is the sample I used : <Window x:Class="WpfApplication198.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 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:local="clr-namespace:WpfApplication198" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525">

namespace WpfApplication198 { ///

/// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.DataContext = this; this.ImageWidth = 200d; this.ImageHeight = -200d; }

public double ImageWidth
{
  get;
  set;
}

public double ImageHeight
{
  get;
  set;
}

} }

melmallakh commented 7 years ago

I am getting the same error after updating to Release 3.2. I downloaded the source code and traced it. private void UpdateViewFinderDisplayContentBounds() { ..... // ensure the display panel has a size Size contentSize = _content.RenderSize; Size viewFinderSize = _viewFinderDisplay.AvailableSize; ===== AvailableSize is EMPTY .... _viewFinderDisplay.Scale = scale; scale is -Infinity

This function will raise an exception With and Height cannot be negative

public object Convert( object value, Type targetType, object parameter, CultureInfo culture ) { ..... double scale = _zoombox._viewFinderDisplay.Scale _zoombox._viewboxFactor; Rect result = new Rect( viewport.Left scale, viewport.Top scale, viewport.Width scale, viewport.Height * scale );

melmallakh commented 7 years ago

I fixed the exception by adding the following code to Scale. It checks if the scale is negative it returns 1 ZoomboxViewFinderDisplay internal double Scale { get { if (_scale < 0) return _scale = 1; return _scale; } }

XceedBoucherS commented 7 years ago

Hi, I understand the error, but can you submit a sample and the steps to reproduce it so I can test the problem ? Thanks.

melmallakh commented 7 years ago

Hi, I am using the Zoombox in a user control that is placed on the main window <UserControl x:Class="Digitizer.View.DTBoardView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:DTBoardView="clr-namespace:Digitizer.BoardView;assembly=Digitizer.BoardView"
xmlns:DTUtilitiesConverter="clr-namespace:Digitizer.Utilities.Converter;assembly=Digitizer.Utilities"
xmlns:DTGraphics="clr-namespace:Digitizer.Graphics;assembly=Digitizer.Graphics"
xmlns:Digitizer="clr-namespace:Digitizer"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" AllowDrop="True" DragEnter="UserControl_DragEnter" Drop="UserControl_Drop">

XceedBoucherS commented 7 years ago

Hi, I don't get the exception, but I can see the reason why. It will be fixed in v3.6. Thanks.

melmallakh commented 7 years ago

Thank you