init branch

This commit is contained in:
NaBian committed 2019-07-11 01:10:17 +08:00
1 parent a2aa500acf
commit 6025958365
14 files changed
+250 -2

No files matched your search

@@ -102,6 +102,8 @@
public static readonly string CardDemoCtl = nameof(CardDemoCtl);
public static readonly string MagnifierDemoCtl = nameof(MagnifierDemoCtl);
public static readonly string ButtonDemoCtl = nameof(ButtonDemoCtl);
public static readonly string RepeatButtonDemoCtl = nameof(RepeatButtonDemoCtl);
@@ -53,7 +53,8 @@ var controlList = new List<string>
"GridDemoCtl",
"RangeSliderDemoCtl",
"ButtonGroupDemoCtl",
"CardDemoCtl"
"CardDemoCtl",
"MagnifierDemoCtl"
};
var styleList = new List<string>
{
@@ -54,6 +54,9 @@
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\CardDemoCtl.xaml.cs">
<DependentUpon>CardDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\MagnifierDemoCtl.xaml.cs">
<DependentUpon>MagnifierDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\RangeSliderDemoCtl.xaml.cs">
<DependentUpon>RangeSliderDemoCtl.xaml</DependentUpon>
</Compile>
@@ -420,6 +423,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)UserControl\Controls\MagnifierDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)UserControl\Controls\RelativePanelDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -771,6 +771,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 放大镜 的本地化字符串。
/// </summary>
public static string Magnifier {
get {
return ResourceManager.GetString("Magnifier", resourceCulture);
}
}
/// <summary>
/// 查找类似 菜单 的本地化字符串。
/// </summary>
@@ -627,4 +627,7 @@
<data name="TextDialogWithTimer" xml:space="preserve">
<value>TextDialog with timer</value>
</data>
<data name="Magnifier" xml:space="preserve">
<value>Magnifier</value>
</data>
</root>
@@ -627,4 +627,7 @@
<data name="TextDialogWithTimer" xml:space="preserve">
<value>文本对话框,带计时器</value>
</data>
<data name="Magnifier" xml:space="preserve">
<value>放大镜</value>
</data>
</root>
@@ -0,0 +1,15 @@
<UserControl x:Class="HandyControlDemo.UserControl.MagnifierDemoCtl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="{DynamicResource RegionBrush}"
xmlns:hc="https://handyorg.github.io/handycontrol">
<hc:TransitioningContentControl>
<hc:SimplePanel>
<Image Name="ImageDemo" Source="/HandyControlDemo;component/Resources/Img/1.jpg" Stretch="None">
<hc:Magnifier.Instance>
<hc:Magnifier Scale="5"/>
</hc:Magnifier.Instance>
</Image>
</hc:SimplePanel>
</hc:TransitioningContentControl>
</UserControl>
@@ -0,0 +1,10 @@
namespace HandyControlDemo.UserControl
{
public partial class MagnifierDemoCtl
{
public MagnifierDemoCtl()
{
InitializeComponent();
}
}
}
@@ -195,6 +195,11 @@
</hc:StatusSwitchElement.CheckedElement>
</ToggleButton>
<ListBox Name="ListBoxControl" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" BorderThickness="0" SelectionMode="Single" Style="{StaticResource ListBoxTransparent}">
<ListBoxItem Style="{StaticResource ListBoxItemNew}" Tag="{x:Static data:MessageToken.MagnifierDemoCtl}" Content="{x:Static langs:Lang.Magnifier}">
<hc:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/Search_16x.png"/>
</hc:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Tag="{x:Static data:MessageToken.GravatarDemoCtl}" Content="{x:Static langs:Lang.Gravatar}">
<hc:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/User_16x.png"/>
@@ -415,7 +420,7 @@
<Image Source="../../Resources/Img/LeftMainContent/TabPage_16x.png"/>
</hc:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Style="{StaticResource ListBoxItemNew}" Tag="{x:Static data:MessageToken.SideMenuDemoCtl}" Content="{x:Static langs:Lang.SideMenu}">
<ListBoxItem Tag="{x:Static data:MessageToken.SideMenuDemoCtl}" Content="{x:Static langs:Lang.SideMenu}">
<hc:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/MainMenuControl_16x.png"/>
</hc:EdgeElement.LeftContent>
@@ -0,0 +1,142 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using HandyControl.Interactivity;
using HandyControl.Tools.Extension;
namespace HandyControl.Controls
{
[TemplatePart(Name = ElementVisualBrush, Type = typeof(VisualBrush))]
public class Magnifier : Control
{
private Size _viewboxSize;
private Adorner _adorner;
private UIElement _elementTarget;
private const string ElementVisualBrush = "PART_VisualBrush";
private VisualBrush _visualBrush = new VisualBrush();
public static readonly DependencyProperty InstanceProperty = DependencyProperty.RegisterAttached(
"Instance", typeof(Magnifier), typeof(Magnifier), new PropertyMetadata(default(Magnifier), OnMagnifierChanged));
private static void OnMagnifierChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is UIElement target)) return;
var magnifier = (Magnifier)e.NewValue;
magnifier.Target = target;
}
public static void SetInstance(DependencyObject element, Magnifier value)
=> element.SetValue(InstanceProperty, value);
public static Magnifier GetInstance(DependencyObject element)
=> (Magnifier) element.GetValue(InstanceProperty);
internal static readonly DependencyProperty TargetProperty = DependencyProperty.Register(
"Target", typeof(UIElement), typeof(Magnifier), new PropertyMetadata(default(UIElement), OnTargetChanged));
private static void OnTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctl = (Magnifier) d;
ctl.UpdateTarget(ctl._elementTarget, false);
ctl.UpdateTarget((UIElement)e.NewValue, true);
}
internal UIElement Target
{
get => (UIElement)GetValue(TargetProperty);
set => SetValue(TargetProperty, value);
}
public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register(
"Scale", typeof(double), typeof(Magnifier), new PropertyMetadata(5.0, OnScaleChanged));
private static void OnScaleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((Magnifier)d).UpdateViewboxSize();
public double Scale
{
get => (double)GetValue(ScaleProperty);
set => SetValue(ScaleProperty, value);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var visualBrush = GetTemplateChild(ElementVisualBrush) as VisualBrush ?? new VisualBrush();
visualBrush.Viewbox = _visualBrush.Viewbox;
_visualBrush = visualBrush;
}
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
{
base.OnRenderSizeChanged(sizeInfo);
UpdateViewboxSize();
}
private void UpdateViewboxSize() => _viewboxSize = new Size(ActualWidth / Scale, ActualHeight / Scale);
private void UpdateTarget(UIElement element , bool isNew)
{
if (element == null) return;
if (!isNew)
{
element.MouseEnter -= Element_MouseEnter;
element.MouseLeave -= Element_MouseLeave;
element.MouseMove -= Element_MouseMove;
_elementTarget = null;
}
else
{
element.MouseEnter += Element_MouseEnter;
element.MouseLeave += Element_MouseLeave;
element.MouseMove += Element_MouseMove;
_elementTarget = element;
}
}
private void UpdateLocation(Point adornerPoint)
{
var targetPoint = Mouse.GetPosition(Target);
var subX = targetPoint.X - _visualBrush.Viewbox.Width / 2;
var subY = targetPoint.Y - _visualBrush.Viewbox.Height / 2;
_visualBrush.Viewbox = new Rect(new Point(subX, subY), _viewboxSize);
var x = adornerPoint.X - ActualWidth / 2;
var y = adornerPoint.Y - ActualHeight / 2;
Arrange(new Rect(x, y, ActualWidth, ActualHeight));
Console.WriteLine(new Rect(x, y, ActualWidth, ActualHeight));
}
private void Element_MouseMove(object sender, MouseEventArgs e) => UpdateLocation(Mouse.GetPosition(_adorner));
private void Element_MouseLeave(object sender, MouseEventArgs e) => _adorner?.Collapse();
private void Element_MouseEnter(object sender, MouseEventArgs e)
{
if (_adorner == null)
{
var layer = AdornerLayer.GetAdornerLayer(Target);
if (layer == null) return;
_adorner = new AdornerContainer(layer)
{
Child = this
};
layer.Add(_adorner);
}
_adorner.Show();
UpdateLocation(Mouse.GetPosition(_adorner));
}
}
}
@@ -19,6 +19,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\PanelElement.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\PasswordBoxAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\RectangleAttach.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Magnifier.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\ButtonGroup.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Card.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeTrack.cs" />
@@ -354,6 +355,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Base\MagnifierBaseStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Base\SliderBaseStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -646,6 +651,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Magnifier.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\NumericUpDown.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -0,0 +1,31 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Border.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="MagnifierBaseStyle" TargetType="controls:Magnifier">
<Setter Property="IsHitTestVisible" Value="False" />
<Setter Property="Width" Value="180"/>
<Setter Property="Height" Value="180"/>
<Setter Property="BorderThickness" Value="8"/>
<Setter Property="Background" Value="{DynamicResource BackgroundBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:Magnifier">
<Border Style="{StaticResource BorderCircular}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
<Ellipse>
<Ellipse.Fill>
<VisualBrush Visual="{Binding Target,RelativeSource={RelativeSource TemplatedParent}}" ViewboxUnits="Absolute" x:Name="PART_VisualBrush"/>
</Ellipse.Fill>
</Ellipse>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
@@ -0,0 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:HandyControl.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base/MagnifierBaseStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style BasedOn="{StaticResource MagnifierBaseStyle}" TargetType="controls:Magnifier"/>
</ResourceDictionary>
@@ -67,6 +67,7 @@
<ResourceDictionary Source="Col.xaml"/>
<ResourceDictionary Source="Card.xaml"/>
<ResourceDictionary Source="Rectangle.xaml"/>
<ResourceDictionary Source="Magnifier.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>