This commit is contained in:
ShrlAlgo
2025-07-11 09:20:23 +08:00
parent c7b104f44f
commit 4d35cadb56
840 changed files with 102347 additions and 11595 deletions

View File

@@ -34,16 +34,16 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
Resources.MergedDictionaries.Clear();
SizeChanged += ImagePanel_SizeChanged;
viewPanelImage.DoZoomToFit += (_, _) => DoZoomToFit();
ViewPanelImage.DoZoomToFit += (_, _) => DoZoomToFit();
viewPanel.PreviewMouseWheel += ViewPanel_PreviewMouseWheel;
viewPanel.MouseLeftButtonDown += ViewPanel_MouseLeftButtonDown;
viewPanel.MouseMove += ViewPanel_MouseMove;
viewPanel.MouseDoubleClick += ViewPanel_MouseDoubleClick;
ViewPanel.PreviewMouseWheel += ViewPanel_PreviewMouseWheel;
ViewPanel.MouseLeftButtonDown += ViewPanel_MouseLeftButtonDown;
ViewPanel.MouseMove += ViewPanel_MouseMove;
ViewPanel.MouseDoubleClick += ViewPanel_MouseDoubleClick;
viewPanel.ManipulationInertiaStarting += ViewPanel_ManipulationInertiaStarting;
viewPanel.ManipulationStarting += ViewPanel_ManipulationStarting;
viewPanel.ManipulationDelta += ViewPanel_ManipulationDelta;
ViewPanel.ManipulationInertiaStarting += ViewPanel_ManipulationInertiaStarting;
ViewPanel.ManipulationStarting += ViewPanel_ManipulationStarting;
ViewPanel.ManipulationDelta += ViewPanel_ManipulationDelta;
}
public bool ZoomWithControlKey
@@ -152,7 +152,7 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
}
if (ShowZoomLevelInfo)
((Storyboard)zoomLevelInfo.FindResource("StoryboardShowZoomLevelInfo")).Begin();
((Storyboard)ZoomLevelInfo.FindResource("StoryboardShowZoomLevelInfo")).Begin();
}
}
@@ -176,14 +176,14 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
OnPropertyChanged();
if (ImageUriSource == null)
viewPanelImage.Source = _source;
ViewPanelImage.Source = _source;
}
}
public void Dispose()
{
viewPanelImage?.Dispose();
viewPanelImage = null;
ViewPanelImage?.Dispose();
ViewPanelImage = null;
}
public event PropertyChangedEventHandler? PropertyChanged;
@@ -211,7 +211,7 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
private void ViewPanel_ManipulationStarting(object? sender, ManipulationStartingEventArgs e)
{
e.ManipulationContainer = viewPanel;
e.ManipulationContainer = ViewPanel;
e.Mode = ManipulationModes.Scale | ManipulationModes.Translate;
}
@@ -223,19 +223,19 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
Zoom(newZoom);
viewPanel.ScrollToHorizontalOffset(viewPanel.HorizontalOffset - delta.Translation.X);
viewPanel.ScrollToVerticalOffset(viewPanel.VerticalOffset - delta.Translation.Y);
ViewPanel.ScrollToHorizontalOffset(ViewPanel.HorizontalOffset - delta.Translation.X);
ViewPanel.ScrollToVerticalOffset(ViewPanel.VerticalOffset - delta.Translation.Y);
e.Handled = true;
}
private void ViewPanel_MouseLeftButtonDown(object? sender, MouseButtonEventArgs e)
{
e.MouseDevice.Capture(viewPanel);
e.MouseDevice.Capture(ViewPanel);
_dragInitPos = e.GetPosition(viewPanel);
_dragInitPos = e.GetPosition(ViewPanel);
var temp = _dragInitPos.Value; // Point is a type value
temp.Offset(viewPanel.HorizontalOffset, viewPanel.VerticalOffset);
temp.Offset(ViewPanel.HorizontalOffset, ViewPanel.VerticalOffset);
_dragInitPos = temp;
}
@@ -259,10 +259,10 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
e.Handled = true;
var delta = _dragInitPos.Value - e.GetPosition(viewPanel);
var delta = _dragInitPos.Value - e.GetPosition(ViewPanel);
viewPanel.ScrollToHorizontalOffset(delta.X);
viewPanel.ScrollToVerticalOffset(delta.Y);
ViewPanel.ScrollToHorizontalOffset(delta.X);
ViewPanel.ScrollToVerticalOffset(delta.Y);
}
private void ViewPanel_PreviewMouseWheel(object? sender, MouseWheelEventArgs e)
@@ -272,7 +272,7 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
// normal scroll when Control is not pressed, useful for PdfViewer
if (ZoomWithControlKey && (Keyboard.Modifiers & ModifierKeys.Control) == 0)
{
viewPanel.ScrollToVerticalOffset(viewPanel.VerticalOffset - e.Delta);
ViewPanel.ScrollToVerticalOffset(ViewPanel.VerticalOffset - e.Delta);
ImageScrolled?.Invoke(this, e.Delta);
return;
}
@@ -285,18 +285,18 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
public Size GetScrollSize()
{
return new Size(viewPanel.ScrollableWidth, viewPanel.ScrollableHeight);
return new Size(ViewPanel.ScrollableWidth, ViewPanel.ScrollableHeight);
}
public Point GetScrollPosition()
{
return new Point(viewPanel.HorizontalOffset, viewPanel.VerticalOffset);
return new Point(ViewPanel.HorizontalOffset, ViewPanel.VerticalOffset);
}
public void SetScrollPosition(Point point)
{
viewPanel.ScrollToHorizontalOffset(point.X);
viewPanel.ScrollToVerticalOffset(point.Y);
ViewPanel.ScrollToHorizontalOffset(point.X);
ViewPanel.ScrollToVerticalOffset(point.Y);
}
public void DoZoomToFit()
@@ -308,14 +308,14 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
private void UpdateZoomToFitFactor()
{
if (viewPanelImage?.Source == null)
if (ViewPanelImage?.Source == null)
{
ZoomToFitFactor = 1d;
return;
}
var factor = Math.Min(viewPanel.ActualWidth / viewPanelImage.Source.Width,
viewPanel.ActualHeight / viewPanelImage.Source.Height);
var factor = Math.Min(ViewPanel.ActualWidth / ViewPanelImage.Source.Width,
ViewPanel.ActualHeight / ViewPanelImage.Source.Height);
ZoomToFitFactor = factor;
}
@@ -328,7 +328,7 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
public void Zoom(double factor, bool suppressEvent = false, bool isToFit = false)
{
if (viewPanelImage?.Source == null)
if (ViewPanelImage?.Source == null)
return;
// pause when fit width
@@ -356,21 +356,21 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
ZoomFactor = factor;
var position = ZoomToFit
? new Point(viewPanelImage.Source.Width / 2, viewPanelImage.Source.Height / 2)
: Mouse.GetPosition(viewPanelImage);
? new Point(ViewPanelImage.Source.Width / 2, ViewPanelImage.Source.Height / 2)
: Mouse.GetPosition(ViewPanelImage);
viewPanelImage.LayoutTransform = new ScaleTransform(factor, factor);
ViewPanelImage.LayoutTransform = new ScaleTransform(factor, factor);
viewPanel.InvalidateMeasure();
ViewPanel.InvalidateMeasure();
// critical for calculating offset
viewPanel.ScrollToHorizontalOffset(0);
viewPanel.ScrollToVerticalOffset(0);
ViewPanel.ScrollToHorizontalOffset(0);
ViewPanel.ScrollToVerticalOffset(0);
UpdateLayout();
var offset = viewPanelImage.TranslatePoint(position, viewPanel) - Mouse.GetPosition(viewPanel);
viewPanel.ScrollToHorizontalOffset(offset.X);
viewPanel.ScrollToVerticalOffset(offset.Y);
var offset = ViewPanelImage.TranslatePoint(position, ViewPanel) - Mouse.GetPosition(ViewPanel);
ViewPanel.ScrollToHorizontalOffset(offset.X);
ViewPanel.ScrollToVerticalOffset(offset.Y);
UpdateLayout();
if (!suppressEvent)
@@ -400,11 +400,11 @@ public partial class ImageView : UserControl, INotifyPropertyChanged, IDisposabl
public void ScrollToTop()
{
viewPanel.ScrollToTop();
ViewPanel.ScrollToTop();
}
public void ScrollToBottom()
{
viewPanel.ScrollToBottom();
ViewPanel.ScrollToBottom();
}
}

View File

@@ -1,16 +1,16 @@
<UserControl
d:DesignHeight="300"
d:DesignWidth="300"
mc:Ignorable="d"
x:Class="WPFluent.Controls.ImageView"
x:Name="ImagePanel"
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:local="clr-namespace:WPFluent.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="imagePanel"
d:DesignHeight="300"
d:DesignWidth="300"
mc:Ignorable="d">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Rectangle RenderOptions.BitmapScalingMode="NearestNeighbor" Visibility="{Binding BackgroundVisibility, ElementName=imagePanel}">
<Rectangle RenderOptions.BitmapScalingMode="NearestNeighbor" Visibility="{Binding BackgroundVisibility, ElementName=ImagePanel}">
<Rectangle.Fill>
<ImageBrush
AlignmentY="Top"
@@ -23,34 +23,34 @@
</Rectangle.Fill>
</Rectangle>
<ScrollViewer
x:Name="viewPanel"
BorderThickness="0"
Focusable="False"
HorizontalScrollBarVisibility="Auto"
IsManipulationEnabled="True"
VerticalScrollBarVisibility="Auto">
VerticalScrollBarVisibility="Auto"
x:Name="ViewPanel">
<local:AnimatedImage
x:Name="viewPanelImage"
AnimationUri="{Binding ImageUriSource, ElementName=imagePanel}"
RenderOptions.BitmapScalingMode="{Binding RenderMode, ElementName=imagePanel}"
Stretch="None" />
AnimationUri="{Binding ImageUriSource, ElementName=ImagePanel}"
RenderOptions.BitmapScalingMode="{Binding RenderMode, ElementName=ImagePanel}"
Stretch="None"
x:Name="ViewPanelImage" />
</ScrollViewer>
<Border
x:Name="zoomLevelInfo"
Padding="15,4,15,4"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Gray"
CornerRadius="5"
HorizontalAlignment="Center"
IsHitTestVisible="False"
Opacity="0">
Opacity="0"
Padding="15,4,15,4"
VerticalAlignment="Center"
x:Name="ZoomLevelInfo">
<TextBlock
FontSize="18"
Foreground="White"
Text="{Binding ElementName=imagePanel, Path=ZoomFactor, StringFormat={}{0:P0}}" />
Text="{Binding ElementName=ImagePanel, Path=ZoomFactor, StringFormat={}{0:P0}}" />
<Border.Resources>
<Storyboard x:Key="StoryboardShowZoomLevelInfo">
<DoubleAnimationUsingKeyFrames Storyboard.Target="{Binding Source={x:Reference zoomLevelInfo}}" Storyboard.TargetProperty="Opacity">
<DoubleAnimationUsingKeyFrames Storyboard.Target="{Binding Source={x:Reference ZoomLevelInfo}}" Storyboard.TargetProperty="Opacity">
<DoubleAnimationUsingKeyFrames.KeyFrames>
<LinearDoubleKeyFrame KeyTime="0:0:0.1" Value="0.9" />
<LinearDoubleKeyFrame KeyTime="0:0:0.6" Value="0.9" />