Skip to content

Commit

Permalink
Add Magnifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghislain1 committed Aug 11, 2023
1 parent 66815eb commit a816dce
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Ghis.Controls.Test/Magnifier/MagnifierTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Ghis.Controls.Test.Magnifier;

using Ghis.Controls.Test.Shared;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ghis.Controls.Magnifier;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -18,6 +19,7 @@ namespace Ghis.Controls.Test.Magnifier;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;

[TestClass]
public class MagnifierTest
Expand All @@ -26,14 +28,12 @@ public class MagnifierTest
public void Show_Magnifier_InAction_Test()
{
var content = new UserControl();
var urlString = @"pack://application:,,,/ Ghis.Controls;component/Assets/images/background.love.jpg";
//content.Height = 400;
//content.Width = 400;
// Image Source = "pack://application:,,,/WPFDevelopers.Samples;component/Resources/Images/Craouse/0.jpg"
var urlString = @"pack://application:,,,/ Ghis.Controls;component/Assets/images/background.love.jpg";
var image = new Image() { Source = new BitmapImage(new Uri(urlString, UriKind.Absolute))};

image.Margin = new System.Windows.Thickness(10);
content.Background = Brushes.AliceBlue;
content.Content= image;
image.SetValue(Magnifier.AddProperty, Magnifier.Default);
WpfInteraction.ShowDialog(content);
}
}
Expand Down
51 changes: 51 additions & 0 deletions Ghis.Controls/Assets/Magnifier.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Ghis.Controls.Magnifier">
<ResourceDictionary.MergedDictionaries>
<!--<ResourceDictionary Source="Basic/ControlBasic.xaml" />-->
</ResourceDictionary.MergedDictionaries>
<Style x:Key="WD.Magnifier"
TargetType="{x:Type controls:Magnifier}">
<Setter Property="HorizontalAlignment"
Value="Left" />
<Setter Property="VerticalAlignment"
Value="Top" />
<Setter Property="IsHitTestVisible"
Value="False" />
<Setter Property="Width"
Value="200" />
<Setter Property="Height"
Value="200" />
<Setter Property="BorderThickness"
Value="8" />
<Setter Property="BorderBrush"
Value="GreenYellow" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:Magnifier}">
<Canvas Name="PART_Canvas">
<Border x:Name="PART_Border"
Width="{TemplateBinding Height}"
Height="{TemplateBinding Height}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<Ellipse>
<Ellipse.Fill>
<VisualBrush x:Name="PART_VisualBrush"
ViewboxUnits="Absolute"
Visual="{Binding ParentTarget, RelativeSource={RelativeSource TemplatedParent}}" />
</Ellipse.Fill>
</Ellipse>
</Border>
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style BasedOn="{StaticResource WD.Magnifier}"
TargetType="{x:Type controls:Magnifier}" />

</ResourceDictionary>
12 changes: 12 additions & 0 deletions Ghis.Controls/Ghis.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<SignAssembly>True</SignAssembly>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
</PropertyGroup>

<ItemGroup>
<None Remove="Assets\images\background.love.jpg" />
</ItemGroup>



Expand All @@ -25,6 +29,14 @@
<PackagePath></PackagePath>
</None>
</ItemGroup>



<ItemGroup>
<Resource Include="Assets\images\background.love.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
</ItemGroup>


</Project>
5 changes: 4 additions & 1 deletion Ghis.Controls/Magnifier/Magnifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ private void Element_MouseMove(object sender, MouseEventArgs e)

private void MoveMagnifier()
{
if (_border == null) return;
if (_border == null)
{
return;
}
var length = Width * _factor;
var radius = length / 2;
var parentTargetPoint = Mouse.GetPosition(ParentTarget);
Expand Down
1 change: 1 addition & 0 deletions Ghis.Controls/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ResourceDictionary Source="/Ghis.Controls;component/Assets/GhisBusyIndicator.xaml"/>
<ResourceDictionary Source="/Ghis.Controls;component/Assets/LineChartAndPieChart.xaml"/>
<ResourceDictionary Source="/Ghis.Controls;component/Assets/GhisTabHeaderControl.xaml" />
<ResourceDictionary Source="/Ghis.Controls;component/Assets/Magnifier.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Arugment used inside the element in MergedDictionaries !!! up -->
<SolidColorBrush x:Key="Accent" Color="Green" />
Expand Down

0 comments on commit a816dce

Please sign in to comment.