fixed a bug of ImageBrowser
This commit is contained in:
1 parent
86b634e85c
commit
084cd55af6
2 files changed
+19
-10
No files matched your search
@@ -170,6 +170,8 @@ namespace HandyControl.Controls
|
|||||||
CommandBindings.Add(new CommandBinding(ControlCommands.Enlarge, ButtonEnlarge_OnClick));
|
CommandBindings.Add(new CommandBinding(ControlCommands.Enlarge, ButtonEnlarge_OnClick));
|
||||||
CommandBindings.Add(new CommandBinding(ControlCommands.RotateLeft, ButtonRotateLeft_OnClick));
|
CommandBindings.Add(new CommandBinding(ControlCommands.RotateLeft, ButtonRotateLeft_OnClick));
|
||||||
CommandBindings.Add(new CommandBinding(ControlCommands.RotateRight, ButtonRotateRight_OnClick));
|
CommandBindings.Add(new CommandBinding(ControlCommands.RotateRight, ButtonRotateRight_OnClick));
|
||||||
|
|
||||||
|
Loaded += (s, e) => Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -210,7 +212,13 @@ namespace HandyControl.Controls
|
|||||||
"ShowImgMap", typeof(bool), typeof(ImageViewer), new PropertyMetadata(ValueBoxes.FalseBox));
|
"ShowImgMap", typeof(bool), typeof(ImageViewer), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||||
|
|
||||||
public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
|
||||||
"ImageSource", typeof(BitmapFrame), typeof(ImageViewer), new PropertyMetadata(default(BitmapFrame)));
|
"ImageSource", typeof(BitmapFrame), typeof(ImageViewer), new PropertyMetadata(default(BitmapFrame), OnImageSourceChanged));
|
||||||
|
|
||||||
|
private static void OnImageSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var ctl = (ImageViewer) d;
|
||||||
|
ctl.Init();
|
||||||
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty IsFullScreenProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty IsFullScreenProperty = DependencyProperty.Register(
|
||||||
"IsFullScreen", typeof(bool), typeof(ImageViewer), new PropertyMetadata(ValueBoxes.FalseBox));
|
"IsFullScreen", typeof(bool), typeof(ImageViewer), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||||
@@ -416,7 +424,7 @@ namespace HandyControl.Controls
|
|||||||
_canvasSmallImg.MouseLeave += CanvasSmallImg_OnMouseLeave;
|
_canvasSmallImg.MouseLeave += CanvasSmallImg_OnMouseLeave;
|
||||||
}
|
}
|
||||||
|
|
||||||
Init();
|
_borderSmallIsLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnImageScaleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
private static void OnImageScaleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
@@ -434,7 +442,7 @@ namespace HandyControl.Controls
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Init()
|
private void Init()
|
||||||
{
|
{
|
||||||
if (ImageSource == null) return;
|
if (ImageSource == null || !IsLoaded) return;
|
||||||
|
|
||||||
double width;
|
double width;
|
||||||
double height;
|
double height;
|
||||||
@@ -464,23 +472,22 @@ namespace HandyControl.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
_imgWidHeiScale = width / height;
|
_imgWidHeiScale = width / height;
|
||||||
Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
var scaleWindow = ActualWidth / ActualHeight;
|
||||||
var scaleWindow = DesiredSize.Width / DesiredSize.Height;
|
|
||||||
if (_imgWidHeiScale > scaleWindow)
|
if (_imgWidHeiScale > scaleWindow)
|
||||||
{
|
{
|
||||||
if (width > DesiredSize.Width)
|
if (width > ActualWidth)
|
||||||
ImageScale = DesiredSize.Width / width;
|
ImageScale = ActualWidth / width;
|
||||||
}
|
}
|
||||||
else if (height > DesiredSize.Height)
|
else if (height > ActualHeight)
|
||||||
{
|
{
|
||||||
ImageScale = DesiredSize.Height / height;
|
ImageScale = ActualHeight / height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImageScale = 1;
|
ImageScale = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageMargin = new Thickness((DesiredSize.Width - ImageWidth) / 2, (DesiredSize.Height - ImageHeight) / 2, 0, 0);
|
ImageMargin = new Thickness((ActualWidth - ImageWidth) / 2, (ActualHeight - ImageHeight) / 2, 0, 0);
|
||||||
|
|
||||||
_imgActualScale = ImageScale;
|
_imgActualScale = ImageScale;
|
||||||
_imgActualMargin = ImageMargin;
|
_imgActualMargin = ImageMargin;
|
||||||
@@ -643,6 +650,7 @@ namespace HandyControl.Controls
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitBorderSmall()
|
private void InitBorderSmall()
|
||||||
{
|
{
|
||||||
|
if (_canvasSmallImg == null) return;
|
||||||
var scaleWindow = _canvasSmallImg.MaxWidth / _canvasSmallImg.MaxHeight;
|
var scaleWindow = _canvasSmallImg.MaxWidth / _canvasSmallImg.MaxHeight;
|
||||||
if (_imgWidHeiScale > scaleWindow)
|
if (_imgWidHeiScale > scaleWindow)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ namespace HandyControl.Controls
|
|||||||
{
|
{
|
||||||
_imageViewer.ImageSource = BitmapFrame.Create(uri);
|
_imageViewer.ImageSource = BitmapFrame.Create(uri);
|
||||||
_imageViewer.ImgPath = uri.AbsolutePath;
|
_imageViewer.ImgPath = uri.AbsolutePath;
|
||||||
|
|
||||||
if (File.Exists(_imageViewer.ImgPath))
|
if (File.Exists(_imageViewer.ImgPath))
|
||||||
{
|
{
|
||||||
var info = new FileInfo(_imageViewer.ImgPath);
|
var info = new FileInfo(_imageViewer.ImgPath);
|
||||||
|
|||||||
Reference in new issue
Block a user