Browse Source

Resize PanelMoveAdorner and ContainerDragHandle when Zoomed, So you can also Move Controls when Zoomed Out very wide!

pull/52/head
jkuehner 12 years ago
parent
commit
5550b1991e
  1. 26
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ContainerDragHandle.cs
  2. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs
  3. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs
  4. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs
  5. 103
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/UIHelpers.cs
  6. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

26
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ContainerDragHandle.cs

@ -9,6 +9,9 @@ using System.Windows.Shapes; @@ -9,6 +9,9 @@ using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
@ -24,5 +27,28 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -24,5 +27,28 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
//This style is defined in themes\generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(typeof(ContainerDragHandle), new FrameworkPropertyMetadata(typeof(ContainerDragHandle)));
}
private ScaleTransform scaleTransform;
public ContainerDragHandle()
{
scaleTransform = new ScaleTransform(1.0, 1.0);
this.LayoutTransform = scaleTransform;
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var surface = this.TryFindParent<DesignSurface>();
if (surface != null && surface.ZoomControl != null)
{
var bnd = new Binding("CurrentZoom") { Source = surface.ZoomControl };
bnd.Converter = InvertedZoomConverter.Instance;
BindingOperations.SetBinding(scaleTransform, ScaleTransform.ScaleXProperty, bnd);
BindingOperations.SetBinding(scaleTransform, ScaleTransform.ScaleYProperty, bnd);
}
}
}
}

28
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs

@ -9,6 +9,10 @@ using System.Windows.Controls; @@ -9,6 +9,10 @@ using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
@ -17,12 +21,17 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -17,12 +21,17 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
static PanelMoveAdorner()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(PanelMoveAdorner),
new FrameworkPropertyMetadata(typeof(PanelMoveAdorner)));
new FrameworkPropertyMetadata(typeof(PanelMoveAdorner)));
}
private ScaleTransform scaleTransform;
public PanelMoveAdorner(DesignItem item)
{
this.item = item;
scaleTransform = new ScaleTransform(1.0, 1.0);
this.LayoutTransform = scaleTransform;
}
DesignItem item;
@ -30,8 +39,23 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -30,8 +39,23 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
e.Handled = true;
item.Services.Selection.SetSelectedComponents(new DesignItem [] { item }, SelectionTypes.Auto);
item.Services.Selection.SetSelectedComponents(new DesignItem [] { item }, SelectionTypes.Auto);
new DragMoveMouseGesture(item, false).Start(item.Services.DesignPanel, e);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var surface = this.TryFindParent<DesignSurface>();
if (surface != null && surface.ZoomControl != null)
{
var bnd = new Binding("CurrentZoom") {Source = surface.ZoomControl};
bnd.Converter = InvertedZoomConverter.Instance;
BindingOperations.SetBinding(scaleTransform, ScaleTransform.ScaleXProperty, bnd);
BindingOperations.SetBinding(scaleTransform, ScaleTransform.ScaleYProperty, bnd);
}
}
}
}

16
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs

@ -235,4 +235,20 @@ namespace ICSharpCode.WpfDesign.Designer.Converters @@ -235,4 +235,20 @@ namespace ICSharpCode.WpfDesign.Designer.Converters
return Enum.Parse(targetType, parameterString);
}
}
public class InvertedZoomConverter : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly InvertedZoomConverter Instance = new InvertedZoomConverter();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return 1.0 / ((double)value);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return 1.0 / ((double)value);
}
}
}

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs

@ -61,7 +61,6 @@ namespace ICSharpCode.WpfDesign.Designer @@ -61,7 +61,6 @@ namespace ICSharpCode.WpfDesign.Designer
internal DesignPanel _designPanel;
private ContentControl _partDesignContent;
private ZoomControl _zoom;
private Border _sceneContainer;
public override void OnApplyTemplate()
@ -69,19 +68,21 @@ namespace ICSharpCode.WpfDesign.Designer @@ -69,19 +68,21 @@ namespace ICSharpCode.WpfDesign.Designer
_partDesignContent = this.Template.FindName("PART_DesignContent", this) as ContentControl;
_partDesignContent.Content = _designPanel;
this._zoom = this.Template.FindName("PART_Zoom", this) as ZoomControl;
this.ZoomControl = this.Template.FindName("PART_Zoom", this) as ZoomControl;
base.OnApplyTemplate();
}
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
{
if (_zoom != null && e.OriginalSource == _zoom)
if (ZoomControl != null && e.OriginalSource == ZoomControl)
{
UnselectAll();
}
}
public ZoomControl ZoomControl { get; private set; }
DesignContext _designContext;
/// <summary>

103
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/UIHelpers.cs

@ -0,0 +1,103 @@ @@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
namespace ICSharpCode.WpfDesign
{
public static class UIHelpers
{
public static DependencyObject GetParentObject(this DependencyObject child)
{
if (child == null) return null;
var contentElement = child as ContentElement;
if (contentElement != null)
{
DependencyObject parent = ContentOperations.GetParent(contentElement);
if (parent != null) return parent;
var fce = contentElement as FrameworkContentElement;
return fce != null ? fce.Parent : null;
}
var frameworkElement = child as FrameworkElement;
if (frameworkElement != null)
{
DependencyObject parent = frameworkElement.Parent;
if (parent != null) return parent;
}
return VisualTreeHelper.GetParent(child);
}
public static T TryFindParent<T>(this DependencyObject child) where T : DependencyObject
{
DependencyObject parentObject = GetParentObject(child);
if (parentObject == null) return null;
T parent = parentObject as T;
if (parent != null)
{
return parent;
}
return TryFindParent<T>(parentObject);
}
public static T TryFindChild<T>(this DependencyObject parent) where T : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(parent, i);
if (child is T)
{
return (T)child;
}
child = TryFindChild<T>(child);
if (child != null)
{
return (T)child;
}
}
return null;
}
public static T TryFindChild<T>(DependencyObject parent, string childName) where T : DependencyObject
{
if (parent == null) return null;
T foundChild = null;
var childrenCount = VisualTreeHelper.GetChildrenCount(parent);
for (var i = 0; i < childrenCount; i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
var childType = child as T;
if (childType == null)
{
foundChild = TryFindChild<T>(child, childName);
if (foundChild != null) break;
}
else if (!string.IsNullOrEmpty(childName))
{
var frameworkElement = child as FrameworkElement;
if (frameworkElement != null && frameworkElement.Name == childName)
{
foundChild = (T)child;
break;
}
}
else
{
foundChild = (T)child;
break;
}
}
return foundChild;
}
}
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

@ -117,6 +117,7 @@ @@ -117,6 +117,7 @@
<Compile Include="ServiceRequiredException.cs" />
<Compile Include="Services.cs" />
<Compile Include="Tools.cs" />
<Compile Include="UIHelpers.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="PropertyGrid\Editors\ComboBoxEditor.xaml">

Loading…
Cancel
Save