Browse Source

Fixes for Unit Tests and Whitespace

pull/584/head
jogibear9988 11 years ago
parent
commit
39e5da367e
  1. 44
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs
  2. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs
  3. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
  4. 126
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  5. 60
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml
  6. 57
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml.cs
  7. 29
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenuExtension.cs
  8. 34
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml
  9. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml.cs
  10. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs
  11. 26
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs
  12. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml
  13. 37
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs
  14. 46
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs
  15. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml
  16. 14
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml.cs
  17. 29
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenuExtension.cs
  18. 660
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  19. 1616
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml
  20. 364
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs
  21. 112
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs
  22. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/PlacementTests.cs
  23. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/MarkupExtensionTests.cs
  24. 53
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs

44
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs

@ -145,10 +145,10 @@ namespace ICSharpCode.WpfDesign.Designer
Metadata.AddPopularProperty(TreeViewItem.IsSelectedProperty); Metadata.AddPopularProperty(TreeViewItem.IsSelectedProperty);
Metadata.AddPopularProperty(Border.PaddingProperty); Metadata.AddPopularProperty(Border.PaddingProperty);
Metadata.AddPopularProperty(Shape.StretchProperty); Metadata.AddPopularProperty(Shape.StretchProperty);
Metadata.AddPopularProperty(Control.VerticalContentAlignmentProperty); Metadata.AddPopularProperty(Control.VerticalContentAlignmentProperty);
Metadata.AddPopularProperty(Control.HorizontalContentAlignmentProperty); Metadata.AddPopularProperty(Control.HorizontalContentAlignmentProperty);
Metadata.AddPopularProperty(Grid.RowProperty); Metadata.AddPopularProperty(Grid.RowProperty);
Metadata.AddPopularProperty(Grid.RowSpanProperty); Metadata.AddPopularProperty(Grid.RowSpanProperty);
Metadata.AddPopularProperty(Grid.ColumnProperty); Metadata.AddPopularProperty(Grid.ColumnProperty);
Metadata.AddPopularProperty(Grid.ColumnSpanProperty); Metadata.AddPopularProperty(Grid.ColumnSpanProperty);
@ -261,30 +261,30 @@ namespace ICSharpCode.WpfDesign.Designer
Metadata.AddPopularControl(typeof(Viewport3D)); Metadata.AddPopularControl(typeof(Viewport3D));
Metadata.AddPopularControl(typeof(WrapPanel)); Metadata.AddPopularControl(typeof(WrapPanel));
//Basic Metadata Size of double.NaN, means no Size should be set. //Basic Metadata Size of double.NaN, means no Size should be set.
Metadata.AddDefaultSize(typeof(TextBlock), new Size(double.NaN, double.NaN)); Metadata.AddDefaultSize(typeof(TextBlock), new Size(double.NaN, double.NaN));
Metadata.AddDefaultSize(typeof(CheckBox), new Size(double.NaN, double.NaN)); Metadata.AddDefaultSize(typeof(CheckBox), new Size(double.NaN, double.NaN));
Metadata.AddDefaultSize(typeof(Image), new Size(double.NaN, double.NaN)); Metadata.AddDefaultSize(typeof(Image), new Size(double.NaN, double.NaN));
Metadata.AddDefaultSize(typeof(UIElement), new Size(120, 100)); Metadata.AddDefaultSize(typeof(UIElement), new Size(120, 100));
Metadata.AddDefaultSize(typeof(ContentControl), new Size(120, 20)); Metadata.AddDefaultSize(typeof(ContentControl), new Size(120, 20));
Metadata.AddDefaultSize(typeof(Button), new Size(75, 23)); Metadata.AddDefaultSize(typeof(Button), new Size(75, 23));
Metadata.AddDefaultSize(typeof(ToggleButton), new Size(75, 23)); Metadata.AddDefaultSize(typeof(ToggleButton), new Size(75, 23));
Metadata.AddDefaultSize(typeof(Slider), new Size(120, 20)); Metadata.AddDefaultSize(typeof(Slider), new Size(120, 20));
Metadata.AddDefaultSize(typeof(TextBox), new Size(120, 20)); Metadata.AddDefaultSize(typeof(TextBox), new Size(120, 20));
Metadata.AddDefaultSize(typeof(PasswordBox), new Size(120, 20)); Metadata.AddDefaultSize(typeof(PasswordBox), new Size(120, 20));
Metadata.AddDefaultSize(typeof(ComboBox), new Size(120, 20)); Metadata.AddDefaultSize(typeof(ComboBox), new Size(120, 20));
Metadata.AddDefaultSize(typeof(ProgressBar), new Size(120, 20)); Metadata.AddDefaultSize(typeof(ProgressBar), new Size(120, 20));
Metadata.AddDefaultSize(typeof(ToolBar), new Size(120, 20)); Metadata.AddDefaultSize(typeof(ToolBar), new Size(120, 20));
Metadata.AddDefaultSize(typeof(Menu), new Size(120, 20)); Metadata.AddDefaultSize(typeof(Menu), new Size(120, 20));
Metadata.AddDefaultSize(typeof(InkCanvas), new Size(120, 120)); Metadata.AddDefaultSize(typeof(InkCanvas), new Size(120, 120));
Metadata.AddDefaultSize(typeof(TreeView), new Size(120, 120)); Metadata.AddDefaultSize(typeof(TreeView), new Size(120, 120));
Metadata.AddDefaultSize(typeof(Label), new Size(130, 120)); Metadata.AddDefaultSize(typeof(Label), new Size(130, 120));
Metadata.AddDefaultSize(typeof(Expander), new Size(130, 120)); Metadata.AddDefaultSize(typeof(Expander), new Size(130, 120));
} }
} }
} }

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/AdornerLayer.cs

@ -224,18 +224,18 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
foreach (AdornerPanel adorner in this.Children) { foreach (AdornerPanel adorner in this.Children) {
if (adorner.AdornedElement.IsDescendantOf(_designPanel)) if (adorner.AdornedElement.IsDescendantOf(_designPanel))
{ {
var rt = (MatrixTransform) adorner.AdornedElement.TransformToAncestor(_designPanel); var rt = (MatrixTransform) adorner.AdornedElement.TransformToAncestor(_designPanel);
if (adorner.AdornedDesignItem != null && adorner.AdornedDesignItem.Parent != null && adorner.AdornedDesignItem.Parent.View is Canvas && adorner.AdornedElement.RenderSize.Height == 0 && adorner.AdornedElement.RenderSize.Width == 0) if (adorner.AdornedDesignItem != null && adorner.AdornedDesignItem.Parent != null && adorner.AdornedDesignItem.Parent.View is Canvas && adorner.AdornedElement.RenderSize.Height == 0 && adorner.AdornedElement.RenderSize.Width == 0)
{ {
var xOffset = rt.Matrix.OffsetX - (((FrameworkElement)adorner.AdornedElement).Width / 2); var xOffset = rt.Matrix.OffsetX - (((FrameworkElement)adorner.AdornedElement).Width / 2);
var yOffset = rt.Matrix.OffsetY - (((FrameworkElement)adorner.AdornedElement).Height / 2); var yOffset = rt.Matrix.OffsetY - (((FrameworkElement)adorner.AdornedElement).Height / 2);
rt = new MatrixTransform(new Matrix(rt.Matrix.M11, rt.Matrix.M12, rt.Matrix.M21, rt.Matrix.M22, xOffset, yOffset)); rt = new MatrixTransform(new Matrix(rt.Matrix.M11, rt.Matrix.M12, rt.Matrix.M21, rt.Matrix.M22, xOffset, yOffset));
} }
adorner.RenderTransform = rt; adorner.RenderTransform = rt;
} }
adorner.Arrange(new Rect(new Point(0, 0), adorner.DesiredSize)); adorner.Arrange(new Rect(new Point(0, 0), adorner.DesiredSize));
} }
return finalSize; return finalSize;
} }

38
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml

@ -2,7 +2,7 @@
<!-- <!--
This file contains the default styles used by the Controls in ICSharpCode.WpfDesign.Designer.Controls This file contains the default styles used by the Controls in ICSharpCode.WpfDesign.Designer.Controls
--> -->
<Converters:LevelConverter x:Key="FormatDoubleConverter" /> <Converters:LevelConverter x:Key="FormatDoubleConverter" />
<ControlConvertors:HandleLengthWithOffset x:Key="HandleLengthWithOffset" /> <ControlConvertors:HandleLengthWithOffset x:Key="HandleLengthWithOffset" />
<SolidColorBrush Color="#FF474747" x:Key="HandleBrush" /> <SolidColorBrush Color="#FF474747" x:Key="HandleBrush" />
<Style TargetType="{x:Type Controls:PanelMoveAdorner}"> <Style TargetType="{x:Type Controls:PanelMoveAdorner}">
@ -335,15 +335,15 @@
<Path SnapsToDevicePixels="True" Grid.Row="0" Stroke="#AC0000" StrokeThickness="1.0" Data="M0,0 L1,0 M0.75,0 L0.75,1" Stretch="Fill" /> <Path SnapsToDevicePixels="True" Grid.Row="0" Stroke="#AC0000" StrokeThickness="1.0" Data="M0,0 L1,0 M0.75,0 L0.75,1" Stretch="Fill" />
<TextBlock HorizontalAlignment="Center" Margin="8,0,0,1" Padding="1,1,1,1" FontSize="10" Grid.Row="1"> <TextBlock HorizontalAlignment="Center" Margin="8,0,0,1" Padding="1,1,1,1" FontSize="10" Grid.Row="1">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding Converter="{x:Static Converters:ControlToRealHeightConverter.Instance}" StringFormat="0"> <MultiBinding Converter="{x:Static Converters:ControlToRealHeightConverter.Instance}" StringFormat="0">
<MultiBinding.Bindings> <MultiBinding.Bindings>
<Binding /> <Binding />
<Binding Path="ActualHeight" UpdateSourceTrigger="PropertyChanged" /> <Binding Path="ActualHeight" UpdateSourceTrigger="PropertyChanged" />
<Binding Path="Height" UpdateSourceTrigger="PropertyChanged" /> <Binding Path="Height" UpdateSourceTrigger="PropertyChanged" />
</MultiBinding.Bindings> </MultiBinding.Bindings>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
<TextBlock.LayoutTransform> <TextBlock.LayoutTransform>
<RotateTransform Angle="270" CenterX="0.5" CenterY="0.5" /> <RotateTransform Angle="270" CenterX="0.5" CenterY="0.5" />
</TextBlock.LayoutTransform> </TextBlock.LayoutTransform>
</TextBlock> </TextBlock>
@ -366,15 +366,15 @@
<Path Grid.Column="0" Stroke="#AC0000" StrokeThickness="1" Data="M0,0 L0,1 M0,0.75 L1,0.75" Stretch="Fill" SnapsToDevicePixels="True" /> <Path Grid.Column="0" Stroke="#AC0000" StrokeThickness="1" Data="M0,0 L0,1 M0,0.75 L1,0.75" Stretch="Fill" SnapsToDevicePixels="True" />
<TextBlock HorizontalAlignment="Center" Margin="0,8,0,0" Padding="1,1,1,1" FontSize="10" Grid.Column="1"> <TextBlock HorizontalAlignment="Center" Margin="0,8,0,0" Padding="1,1,1,1" FontSize="10" Grid.Column="1">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding Converter="{x:Static Converters:ControlToRealWidthConverter.Instance}" StringFormat="0"> <MultiBinding Converter="{x:Static Converters:ControlToRealWidthConverter.Instance}" StringFormat="0">
<MultiBinding.Bindings> <MultiBinding.Bindings>
<Binding /> <Binding />
<Binding Path="ActualWidth" UpdateSourceTrigger="PropertyChanged" /> <Binding Path="ActualWidth" UpdateSourceTrigger="PropertyChanged" />
<Binding Path="Width" UpdateSourceTrigger="PropertyChanged" /> <Binding Path="Width" UpdateSourceTrigger="PropertyChanged" />
</MultiBinding.Bindings> </MultiBinding.Bindings>
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
</TextBlock> </TextBlock>
<Path Grid.Column="2" Stroke="#AC0000" StrokeThickness="1" Data="M0,0.75 L3,0.75 M3,0 L3,1 " Stretch="Fill" SnapsToDevicePixels="True" /> <Path Grid.Column="2" Stroke="#AC0000" StrokeThickness="1" Data="M0,0.75 L3,0.75 M3,0 L3,1 " Stretch="Fill" SnapsToDevicePixels="True" />
</Grid> </Grid>
</ControlTemplate> </ControlTemplate>

126
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

@ -62,7 +62,7 @@ namespace ICSharpCode.WpfDesign.Designer
void RunHitTest(Visual reference, Point point, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback) void RunHitTest(Visual reference, Point point, HitTestFilterCallback filterCallback, HitTestResultCallback resultCallback)
{ {
VisualTreeHelper.HitTest(reference, filterCallback, resultCallback, VisualTreeHelper.HitTest(reference, filterCallback, resultCallback,
new PointHitTestParameters(point)); new PointHitTestParameters(point));
} }
HitTestFilterBehavior FilterHitTestInvisibleElements(DependencyObject potentialHitTestTarget) HitTestFilterBehavior FilterHitTestInvisibleElements(DependencyObject potentialHitTestTarget)
@ -95,15 +95,15 @@ namespace ICSharpCode.WpfDesign.Designer
DesignPanelHitTestResult result = DesignPanelHitTestResult.NoHit; DesignPanelHitTestResult result = DesignPanelHitTestResult.NoHit;
HitTest(mousePosition, testAdorners, testDesignSurface, HitTest(mousePosition, testAdorners, testDesignSurface,
delegate(DesignPanelHitTestResult r) { delegate(DesignPanelHitTestResult r) {
result = r; result = r;
return false; return false;
}, hitTestType); }, hitTestType);
return result; return result;
} }
/// <summary> /// <summary>
/// Performs a hit test on the design surface, raising <paramref name="callback"/> for each match. /// Performs a hit test on the design surface, raising <paramref name="callback"/> for each match.
/// Hit testing continues while the callback returns true. /// Hit testing continues while the callback returns true.
/// </summary> /// </summary>
@ -156,8 +156,8 @@ namespace ICSharpCode.WpfDesign.Designer
if (hitTestType == HitTestType.ElementSelection) if (hitTestType == HitTestType.ElementSelection)
{ {
if (Keyboard.IsKeyDown(Key.LeftAlt)) if (Keyboard.IsKeyDown(Key.LeftAlt))
if (lastElement != null && lastElement != _context.RootItem.Component && if (lastElement != null && lastElement != _context.RootItem.Component &&
hitTestElements.Contains(lastElement)) hitTestElements.Contains(lastElement))
{ {
var idx = hitTestElements.IndexOf(lastElement) - 1; var idx = hitTestElements.IndexOf(lastElement) - 1;
if (idx >= 0) if (idx >= 0)
@ -220,18 +220,18 @@ namespace ICSharpCode.WpfDesign.Designer
//Set custom HitTestFilterCallbak //Set custom HitTestFilterCallbak
public HitTestFilterCallback CustomHitTestFilterBehavior { get; set; } public HitTestFilterCallback CustomHitTestFilterBehavior { get; set; }
public AdornerLayer AdornerLayer public AdornerLayer AdornerLayer
{ {
get get
{ {
return _adornerLayer; return _adornerLayer;
} }
} }
/// <summary> /// <summary>
/// Gets/Sets the design context. /// Gets/Sets the design context.
/// </summary> /// </summary>
public DesignContext Context { public DesignContext Context {
get { return _context; } get { return _context; }
set { _context = value; } set { _context = value; }
} }
@ -416,9 +416,9 @@ namespace ICSharpCode.WpfDesign.Designer
if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { if (!Keyboard.IsKeyDown(Key.LeftCtrl)) {
info.Bounds = new Rect(bounds.Left + dx, info.Bounds = new Rect(bounds.Left + dx,
bounds.Top + dy, bounds.Top + dy,
bounds.Width, bounds.Width,
bounds.Height); bounds.Height);
} else { } else {
if (info.OriginalBounds.Width + dx >= 0 && info.OriginalBounds.Height + dy >= 0) { if (info.OriginalBounds.Width + dx >= 0 && info.OriginalBounds.Height + dy >= 0) {
info.Bounds = new Rect(info.OriginalBounds.Left, info.Bounds = new Rect(info.OriginalBounds.Left,
@ -434,9 +434,9 @@ namespace ICSharpCode.WpfDesign.Designer
} }
static bool IsPropertySet(UIElement element, DependencyProperty d) static bool IsPropertySet(UIElement element, DependencyProperty d)
{ {
return element.ReadLocalValue(d) != DependencyProperty.UnsetValue; return element.ReadLocalValue(d) != DependencyProperty.UnsetValue;
} }
protected override void OnQueryCursor(QueryCursorEventArgs e) protected override void OnQueryCursor(QueryCursorEventArgs e)
{ {
@ -457,53 +457,53 @@ namespace ICSharpCode.WpfDesign.Designer
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
} }
#region ContextMenu #region ContextMenu
private Dictionary<ContextMenu, Tuple<int,List<object>>> contextMenusAndEntries = new Dictionary<ContextMenu, Tuple<int,List<object>>>(); private Dictionary<ContextMenu, Tuple<int,List<object>>> contextMenusAndEntries = new Dictionary<ContextMenu, Tuple<int,List<object>>>();
public void AddContextMenu(ContextMenu contextMenu) public void AddContextMenu(ContextMenu contextMenu)
{ {
contextMenusAndEntries.Add(contextMenu, new Tuple<int, List<object>>(contextMenusAndEntries.Count, new List<object>(contextMenu.Items.Cast<object>()))); contextMenusAndEntries.Add(contextMenu, new Tuple<int, List<object>>(contextMenusAndEntries.Count, new List<object>(contextMenu.Items.Cast<object>())));
contextMenu.Items.Clear(); contextMenu.Items.Clear();
UpdateContextMenu(); UpdateContextMenu();
} }
public void RemoveContextMenu(ContextMenu contextMenu) public void RemoveContextMenu(ContextMenu contextMenu)
{ {
contextMenusAndEntries.Remove(contextMenu); contextMenusAndEntries.Remove(contextMenu);
UpdateContextMenu(); UpdateContextMenu();
} }
public void ClearContextMenu() public void ClearContextMenu()
{ {
contextMenusAndEntries.Clear(); contextMenusAndEntries.Clear();
ContextMenu = null; ContextMenu = null;
} }
private void UpdateContextMenu() private void UpdateContextMenu()
{ {
if (contextMenusAndEntries.Count == 0) if (contextMenusAndEntries.Count == 0)
this.ContextMenu = null; this.ContextMenu = null;
if (this.ContextMenu == null) if (this.ContextMenu == null)
this.ContextMenu = new ContextMenu(); this.ContextMenu = new ContextMenu();
this.ContextMenu.Items.Clear(); this.ContextMenu.Items.Clear();
foreach (var entries in contextMenusAndEntries.Values.OrderBy(x => x.Item1).Select(x => x.Item2)) foreach (var entries in contextMenusAndEntries.Values.OrderBy(x => x.Item1).Select(x => x.Item2))
{ {
if (this.ContextMenu.Items.Count > 0) if (this.ContextMenu.Items.Count > 0)
this.ContextMenu.Items.Add(new Separator()); this.ContextMenu.Items.Add(new Separator());
foreach (var entry in entries) foreach (var entry in entries)
{ {
ContextMenu.Items.Add(entry); ContextMenu.Items.Add(entry);
} }
} }
} }
#endregion #endregion
} }
} }

60
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml

@ -2,35 +2,35 @@
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer" xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer"
> >
<MenuItem Header="{Binding ArrangeLeft, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeLeft"> <MenuItem Header="{Binding ArrangeLeft, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeLeft">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-left.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-left.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="{Binding ArrangeHorizontalMiddle, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeHorizontalCentered"> <MenuItem Header="{Binding ArrangeHorizontalMiddle, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeHorizontalCentered">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-center.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-center.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="{Binding ArrangeRight, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeRight"> <MenuItem Header="{Binding ArrangeRight, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeRight">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-right.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-right.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="{Binding ArrangeTop, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeTop"> <MenuItem Header="{Binding ArrangeTop, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeTop">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="{Binding ArrangeVerticalMiddle, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeVerticalCentered"> <MenuItem Header="{Binding ArrangeVerticalMiddle, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeVerticalCentered">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-middle.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-middle.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="{Binding ArrangeBottom, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeBottom"> <MenuItem Header="{Binding ArrangeBottom, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeBottom">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-bottom.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-bottom.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
</ContextMenu> </ContextMenu>

57
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml.cs

@ -17,25 +17,12 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.PropertyGrid;
using ICSharpCode.WpfDesign.Designer.Xaml;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
public partial class ArrangeItemsContextMenu public partial class ArrangeItemsContextMenu
{ {
private DesignItem designItem; private DesignItem designItem;
public ArrangeItemsContextMenu(DesignItem designItem) public ArrangeItemsContextMenu(DesignItem designItem)
@ -50,29 +37,29 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Left); ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Left);
} }
void Click_ArrangeHorizontalCentered(object sender, System.Windows.RoutedEventArgs e) void Click_ArrangeHorizontalCentered(object sender, System.Windows.RoutedEventArgs e)
{ {
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.HorizontalMiddle); ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.HorizontalMiddle);
} }
void Click_ArrangeRight(object sender, System.Windows.RoutedEventArgs e) void Click_ArrangeRight(object sender, System.Windows.RoutedEventArgs e)
{ {
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Right); ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Right);
} }
void Click_ArrangeTop(object sender, System.Windows.RoutedEventArgs e) void Click_ArrangeTop(object sender, System.Windows.RoutedEventArgs e)
{ {
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Top); ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Top);
} }
void Click_ArrangeVerticalCentered(object sender, System.Windows.RoutedEventArgs e) void Click_ArrangeVerticalCentered(object sender, System.Windows.RoutedEventArgs e)
{ {
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.VerticalMiddle); ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.VerticalMiddle);
} }
void Click_ArrangeBottom(object sender, System.Windows.RoutedEventArgs e) void Click_ArrangeBottom(object sender, System.Windows.RoutedEventArgs e)
{ {
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Bottom); ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Bottom);
} }
} }
} }

29
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenuExtension.cs

@ -19,9 +19,6 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer; using ICSharpCode.WpfDesign.Designer;
@ -33,26 +30,28 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// </summary> /// </summary>
[ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))] [ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))]
[ExtensionFor(typeof(UIElement))] [ExtensionFor(typeof(UIElement))]
[Extension(Order = 30)] [Extension(Order = 30)]
public class ArrangeItemsContextMenuExtension : SelectionAdornerProvider public class ArrangeItemsContextMenuExtension : SelectionAdornerProvider
{ {
DesignPanel panel; DesignPanel panel;
ContextMenu contextMenu; ContextMenu contextMenu;
protected override void OnInitialized() protected override void OnInitialized()
{ {
base.OnInitialized(); base.OnInitialized();
contextMenu = new ArrangeItemsContextMenu(ExtendedItem); contextMenu = new ArrangeItemsContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
panel.AddContextMenu(contextMenu); if (panel != null)
} panel.AddContextMenu(contextMenu);
}
protected override void OnRemove() protected override void OnRemove()
{ {
panel.RemoveContextMenu(contextMenu); if (panel != null)
panel.RemoveContextMenu(contextMenu);
base.OnRemove(); base.OnRemove();
} }
} }
} }

34
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml

@ -2,25 +2,25 @@
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer" xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer"
> >
<MenuItem Header="{Binding SendToFrontText, Source={x:Static Translation:Translations.Instance}}" Click="Click_BringToFront"> <MenuItem Header="{Binding SendToFrontText, Source={x:Static Translation:Translations.Instance}}" Click="Click_BringToFront">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-stack-arrange.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-stack-arrange.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="{Binding SendForward, Source={x:Static Translation:Translations.Instance}}" Click="Click_Forward"> <MenuItem Header="{Binding SendForward, Source={x:Static Translation:Translations.Instance}}" Click="Click_Forward">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-arrange.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-arrange.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="{Binding SendBackward, Source={x:Static Translation:Translations.Instance}}" Click="Click_Backward"> <MenuItem Header="{Binding SendBackward, Source={x:Static Translation:Translations.Instance}}" Click="Click_Backward">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-arrange-back.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-arrange-back.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="{Binding SendToBack, Source={x:Static Translation:Translations.Instance}}" Click="Click_SendToBack"> <MenuItem Header="{Binding SendToBack, Source={x:Static Translation:Translations.Instance}}" Click="Click_SendToBack">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-stack-arrange-back.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-stack-arrange-back.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
</ContextMenu> </ContextMenu>

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenu.xaml.cs

@ -19,17 +19,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.PropertyGrid;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {

13
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickContextMenuExtension.cs

@ -19,9 +19,6 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer; using ICSharpCode.WpfDesign.Designer;
@ -36,20 +33,22 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public sealed class RightClickContextMenuExtension : PrimarySelectionAdornerProvider public sealed class RightClickContextMenuExtension : PrimarySelectionAdornerProvider
{ {
DesignPanel panel; DesignPanel panel;
ContextMenu contextMenu; ContextMenu contextMenu;
protected override void OnInitialized() protected override void OnInitialized()
{ {
base.OnInitialized(); base.OnInitialized();
contextMenu = new RightClickContextMenu(ExtendedItem); contextMenu = new RightClickContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
panel.AddContextMenu(contextMenu); if (panel != null)
panel.AddContextMenu(contextMenu);
} }
protected override void OnRemove() protected override void OnRemove()
{ {
panel.RemoveContextMenu(contextMenu); if (panel != null)
panel.RemoveContextMenu(contextMenu);
base.OnRemove(); base.OnRemove();
} }

26
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs

@ -226,20 +226,22 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
if (sender == null || e.PropertyName == "Width" || e.PropertyName == "Height") { if (sender == null || e.PropertyName == "Width" || e.PropertyName == "Height") {
AdornerPanel.SetPlacement(thumb1, AdornerPanel.SetPlacement(thumb1,
new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Top) { new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Top) {
YOffset = 0, YOffset = 0,
XOffset = -1 * PlacementOperation.GetRealElementSize(ExtendedItem.View).Width / 4 XOffset = -1 * PlacementOperation.GetRealElementSize(ExtendedItem.View).Width / 4
}); });
AdornerPanel.SetPlacement(thumb2, AdornerPanel.SetPlacement(thumb2,
new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Center) { new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Center) {
YOffset = -1 * PlacementOperation.GetRealElementSize(ExtendedItem.View).Height / 4, YOffset = -1 * PlacementOperation.GetRealElementSize(ExtendedItem.View).Height / 4,
XOffset = 0 XOffset = 0
}); });
((DesignPanel)this.ExtendedItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true); var designPanel = this.ExtendedItem.Services.DesignPanel as DesignPanel;
} if (designPanel != null)
} designPanel.AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true);
}
}
protected override void OnRemove() protected override void OnRemove()
{ {

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml

@ -2,10 +2,10 @@
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer" xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer"
> >
<MenuItem Header="{Binding FormatedTextEditor, Source={x:Static Translation:Translations.Instance}}" Click="Click_EditFormatedText"> <MenuItem Header="{Binding FormatedTextEditor, Source={x:Static Translation:Translations.Instance}}" Click="Click_EditFormatedText">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/edit.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/edit.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
</ContextMenu> </ContextMenu>

37
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs

@ -17,20 +17,9 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor; using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
using ICSharpCode.WpfDesign.PropertyGrid;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
@ -38,25 +27,25 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
private DesignItem designItem; private DesignItem designItem;
public TextBlockRightClickContextMenu(DesignItem designItem) public TextBlockRightClickContextMenu(DesignItem designItem)
{ {
this.designItem = designItem; this.designItem = designItem;
InitializeComponent(); InitializeComponent();
} }
void Click_EditFormatedText(object sender, RoutedEventArgs e) void Click_EditFormatedText(object sender, RoutedEventArgs e)
{ {
var dlg = new Window() var dlg = new Window()
{ {
Content = new FormatedTextEditor(designItem), Content = new FormatedTextEditor(designItem),
Width = 440, Width = 440,
Height = 200, Height = 200,
WindowStyle = WindowStyle.ToolWindow, WindowStyle = WindowStyle.ToolWindow,
Owner = ((DesignPanel) designItem.Context.Services.DesignPanel).TryFindParent<Window>(), Owner = ((DesignPanel) designItem.Context.Services.DesignPanel).TryFindParent<Window>(),
}; };
dlg.ShowDialog(); dlg.ShowDialog();
} }
} }
} }

46
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs

@ -17,39 +17,37 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
[ExtensionServer(typeof (OnlyOneItemSelectedExtensionServer))] [ExtensionServer(typeof (OnlyOneItemSelectedExtensionServer))]
[ExtensionFor(typeof (TextBlock))] [ExtensionFor(typeof (TextBlock))]
[Extension(Order = 10)] [Extension(Order = 10)]
public class TextBlockRightClickContextMenuExtension : PrimarySelectionAdornerProvider public class TextBlockRightClickContextMenuExtension : PrimarySelectionAdornerProvider
{ {
DesignPanel panel; DesignPanel panel;
ContextMenu contextMenu; ContextMenu contextMenu;
protected override void OnInitialized() protected override void OnInitialized()
{ {
base.OnInitialized(); base.OnInitialized();
contextMenu = new TextBlockRightClickContextMenu(ExtendedItem); contextMenu = new TextBlockRightClickContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
panel.AddContextMenu(contextMenu); if (panel != null)
} panel.AddContextMenu(contextMenu);
}
protected override void OnRemove() protected override void OnRemove()
{ {
panel.RemoveContextMenu(contextMenu); if (panel != null)
panel.RemoveContextMenu(contextMenu);
base.OnRemove(); base.OnRemove();
} }
} }
} }

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml

@ -2,11 +2,11 @@
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer" xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer"
> >
<MenuItem Header="{Binding WrapInCanvas, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInCanvas" /> <MenuItem Header="{Binding WrapInCanvas, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInCanvas" />
<MenuItem Header="{Binding WrapInGrid, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInGrid"> <MenuItem Header="{Binding WrapInGrid, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInGrid">
<MenuItem.Icon> <MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/grid.png" /> <Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/grid.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
</ContextMenu> </ContextMenu>

14
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml.cs

@ -17,25 +17,13 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.PropertyGrid;
using ICSharpCode.WpfDesign.Designer.Xaml;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
public partial class WrapItemsContextMenu public partial class WrapItemsContextMenu
{ {
private DesignItem designItem; private DesignItem designItem;
public WrapItemsContextMenu(DesignItem designItem) public WrapItemsContextMenu(DesignItem designItem)

29
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenuExtension.cs

@ -19,9 +19,6 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners; using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer; using ICSharpCode.WpfDesign.Designer;
@ -33,26 +30,28 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// </summary> /// </summary>
[ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))] [ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))]
[ExtensionFor(typeof(UIElement))] [ExtensionFor(typeof(UIElement))]
[Extension(Order = 50)] [Extension(Order = 50)]
public class WrapItemsContextMenuExtension : SelectionAdornerProvider public class WrapItemsContextMenuExtension : SelectionAdornerProvider
{ {
DesignPanel panel; DesignPanel panel;
ContextMenu contextMenu; ContextMenu contextMenu;
protected override void OnInitialized() protected override void OnInitialized()
{ {
base.OnInitialized(); base.OnInitialized();
contextMenu = new WrapItemsContextMenu(ExtendedItem); contextMenu = new WrapItemsContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
panel.AddContextMenu(contextMenu); if (panel != null)
} panel.AddContextMenu(contextMenu);
}
protected override void OnRemove() protected override void OnRemove()
{ {
panel.RemoveContextMenu(contextMenu); if (panel != null)
panel.RemoveContextMenu(contextMenu);
base.OnRemove(); base.OnRemove();
} }
} }
} }

660
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs

@ -123,45 +123,45 @@ namespace ICSharpCode.WpfDesign.Designer
{ {
try try
{ {
var fixedDoc = new FixedDocument(); var fixedDoc = new FixedDocument();
var pageContent = new PageContent(); var pageContent = new PageContent();
var fixedPage = new FixedPage(); var fixedPage = new FixedPage();
fixedPage.Children.Add(element); fixedPage.Children.Add(element);
(pageContent as IAddChild).AddChild(fixedPage); (pageContent as IAddChild).AddChild(fixedPage);
fixedDoc.Pages.Add(pageContent); fixedDoc.Pages.Add(pageContent);
var f = new XpsSerializerFactory(); var f = new XpsSerializerFactory();
var w = f.CreateSerializerWriter(new MemoryStream()); var w = f.CreateSerializerWriter(new MemoryStream());
w.Write(fixedDoc); w.Write(fixedDoc);
fixedPage.Children.Remove(element); fixedPage.Children.Remove(element);
} }
catch (Exception) catch (Exception)
{ } { }
} }
internal static Size GetDefaultSize(DesignItem createdItem) internal static Size GetDefaultSize(DesignItem createdItem)
{ {
var defS = Metadata.GetDefaultSize(createdItem.ComponentType, false); var defS = Metadata.GetDefaultSize(createdItem.ComponentType, false);
if (defS != null) if (defS != null)
return defS.Value; return defS.Value;
CreateVisualTree(createdItem.View); CreateVisualTree(createdItem.View);
var s = createdItem.View.DesiredSize; var s = createdItem.View.DesiredSize;
var newS = Metadata.GetDefaultSize(createdItem.ComponentType, true); var newS = Metadata.GetDefaultSize(createdItem.ComponentType, true);
if (newS.HasValue) if (newS.HasValue)
{ {
if (!(s.Width > 5) && newS.Value.Width > 0) if (!(s.Width > 5) && newS.Value.Width > 0)
s.Width = newS.Value.Width; s.Width = newS.Value.Width;
if (!(s.Height > 5) && newS.Value.Height > 0) if (!(s.Height > 5) && newS.Value.Height > 0)
s.Height = newS.Value.Height; s.Height = newS.Value.Height;
} }
if (double.IsNaN(s.Width) && GetWidth(createdItem.View) > 0) { if (double.IsNaN(s.Width) && GetWidth(createdItem.View) > 0) {
s.Width = GetWidth(createdItem.View); s.Width = GetWidth(createdItem.View);
} }
if (double.IsNaN(s.Height) && GetWidth(createdItem.View) > 0) { if (double.IsNaN(s.Height) && GetWidth(createdItem.View) > 0) {
@ -192,16 +192,16 @@ namespace ICSharpCode.WpfDesign.Designer
public static void Resize(DesignItem item, double newWidth, double newHeight) public static void Resize(DesignItem item, double newWidth, double newHeight)
{ {
if (newWidth != GetWidth(item.View)) { if (newWidth != GetWidth(item.View)) {
if(double.IsNaN(newWidth)) if(double.IsNaN(newWidth))
item.Properties.GetProperty(FrameworkElement.WidthProperty).Reset(); item.Properties.GetProperty(FrameworkElement.WidthProperty).Reset();
else else
item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth); item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth);
} }
if (newHeight != GetHeight(item.View)) { if (newHeight != GetHeight(item.View)) {
if (double.IsNaN(newHeight)) if (double.IsNaN(newHeight))
item.Properties.GetProperty(FrameworkElement.HeightProperty).Reset(); item.Properties.GetProperty(FrameworkElement.HeightProperty).Reset();
else else
item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight); item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight);
} }
} }
@ -223,120 +223,120 @@ namespace ICSharpCode.WpfDesign.Designer
public DesignItem DesignItem { get; set; } public DesignItem DesignItem { get; set; }
} }
private static ItemPos GetItemPos(IPlacementBehavior placementBehavior, DesignItem designItem) private static ItemPos GetItemPos(IPlacementBehavior placementBehavior, DesignItem designItem)
{ {
var itemPos = new ItemPos() {DesignItem = designItem}; var itemPos = new ItemPos() {DesignItem = designItem};
var pos = placementBehavior.GetPosition(null, designItem); var pos = placementBehavior.GetPosition(null, designItem);
itemPos.Xmin = pos.X; itemPos.Xmin = pos.X;
itemPos.Xmax = pos.X + pos.Width; itemPos.Xmax = pos.X + pos.Width;
itemPos.Ymin = pos.Y; itemPos.Ymin = pos.Y;
itemPos.Ymax = pos.Y + pos.Height; itemPos.Ymax = pos.Y + pos.Height;
return itemPos; return itemPos;
if (designItem.Parent.Component is Canvas) if (designItem.Parent.Component is Canvas)
{ {
var canvas = designItem.Parent.View as Canvas; var canvas = designItem.Parent.View as Canvas;
if (designItem.Properties.GetAttachedProperty(Canvas.RightProperty) != null && if (designItem.Properties.GetAttachedProperty(Canvas.RightProperty) != null &&
designItem.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) designItem.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{ {
itemPos.HorizontalAlignment = HorizontalAlignment.Right; itemPos.HorizontalAlignment = HorizontalAlignment.Right;
itemPos.Xmax = canvas.ActualWidth - itemPos.Xmax = canvas.ActualWidth -
(double) designItem.Properties.GetAttachedProperty(Canvas.RightProperty).ValueOnInstance; (double) designItem.Properties.GetAttachedProperty(Canvas.RightProperty).ValueOnInstance;
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth; itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth;
} }
else if (designItem.Properties.GetAttachedProperty(Canvas.LeftProperty) != null && else if (designItem.Properties.GetAttachedProperty(Canvas.LeftProperty) != null &&
designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).IsSet) designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).IsSet)
{ {
itemPos.HorizontalAlignment = HorizontalAlignment.Left; itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmin = itemPos.Xmin =
(double) designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance; (double) designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth; itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth;
} }
else else
{ {
itemPos.HorizontalAlignment = HorizontalAlignment.Left; itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth; itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth;
} }
if (designItem.Properties.GetAttachedProperty(Canvas.BottomProperty) != null && if (designItem.Properties.GetAttachedProperty(Canvas.BottomProperty) != null &&
designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
{ {
itemPos.VerticalAlignment = VerticalAlignment.Bottom; itemPos.VerticalAlignment = VerticalAlignment.Bottom;
itemPos.Ymax = canvas.ActualHeight - itemPos.Ymax = canvas.ActualHeight -
(double) (double)
designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).ValueOnInstance; designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).ValueOnInstance;
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight; itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight;
} }
else if (designItem.Properties.GetAttachedProperty(Canvas.TopProperty) != null && else if (designItem.Properties.GetAttachedProperty(Canvas.TopProperty) != null &&
designItem.Properties.GetAttachedProperty(Canvas.TopProperty).IsSet) designItem.Properties.GetAttachedProperty(Canvas.TopProperty).IsSet)
{ {
itemPos.VerticalAlignment = VerticalAlignment.Top; itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymin = itemPos.Ymin =
(double) designItem.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance; (double) designItem.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight; itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight;
} }
else else
{ {
itemPos.VerticalAlignment = VerticalAlignment.Top; itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight; itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight;
} }
} }
else if (designItem.Parent.Component is Grid) else if (designItem.Parent.Component is Grid)
{ {
var grid = designItem.Parent.View as Grid; var grid = designItem.Parent.View as Grid;
if ( if (
(HorizontalAlignment) (HorizontalAlignment)
designItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance == designItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance ==
HorizontalAlignment.Right) HorizontalAlignment.Right)
{ {
itemPos.HorizontalAlignment = HorizontalAlignment.Right; itemPos.HorizontalAlignment = HorizontalAlignment.Right;
itemPos.Xmax = grid.ActualWidth - itemPos.Xmax = grid.ActualWidth -
((Thickness) ((Thickness)
designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
.Right; .Right;
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth; itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth;
} }
else else
{ {
itemPos.HorizontalAlignment = HorizontalAlignment.Left; itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmin = itemPos.Xmin =
((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) ((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
.Left; .Left;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth; itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth;
} }
if ( if (
(VerticalAlignment) (VerticalAlignment)
designItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance == designItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance ==
VerticalAlignment.Bottom) VerticalAlignment.Bottom)
{ {
itemPos.VerticalAlignment = VerticalAlignment.Bottom; itemPos.VerticalAlignment = VerticalAlignment.Bottom;
itemPos.Ymax = grid.ActualHeight - itemPos.Ymax = grid.ActualHeight -
((Thickness) ((Thickness)
designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
.Bottom; .Bottom;
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight; itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight;
} }
else else
{ {
itemPos.VerticalAlignment = VerticalAlignment.Top; itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymin = itemPos.Ymin =
((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance) ((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
.Top; .Top;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight; itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight;
} }
} }
return itemPos; return itemPos;
} }
public static void WrapItemsNewContainer(IEnumerable<DesignItem> items, Type containerType) public static void WrapItemsNewContainer(IEnumerable<DesignItem> items, Type containerType)
{ {
var collection = items; var collection = items;
@ -347,12 +347,12 @@ namespace ICSharpCode.WpfDesign.Designer
if (collection.Any(x => x.Parent != container)) if (collection.Any(x => x.Parent != container))
return; return;
//Change Code to use the Placment Operation! //Change Code to use the Placment Operation!
var placement = container.Extensions.OfType<IPlacementBehavior>().FirstOrDefault(); var placement = container.Extensions.OfType<IPlacementBehavior>().FirstOrDefault();
if (placement == null) if (placement == null)
return; return;
var newInstance = Activator.CreateInstance(containerType); var newInstance = Activator.CreateInstance(containerType);
DesignItem newPanel = _context.Services.Component.RegisterComponentForDesigner(newInstance); DesignItem newPanel = _context.Services.Component.RegisterComponentForDesigner(newInstance);
var changeGroup = newPanel.OpenGroup("Wrap in Container"); var changeGroup = newPanel.OpenGroup("Wrap in Container");
@ -360,7 +360,7 @@ namespace ICSharpCode.WpfDesign.Designer
foreach (var item in collection) { foreach (var item in collection) {
itemList.Add(GetItemPos(placement, item)); itemList.Add(GetItemPos(placement, item));
//var pos = placement.GetPosition(null, item); //var pos = placement.GetPosition(null, item);
if (container.Component is Canvas) { if (container.Component is Canvas) {
item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset();
item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset();
@ -381,7 +381,7 @@ namespace ICSharpCode.WpfDesign.Designer
var ymin = itemList.Min(x => x.Ymin); var ymin = itemList.Min(x => x.Ymin);
var ymax = itemList.Max(x => x.Ymax); var ymax = itemList.Max(x => x.Ymax);
foreach (var item in itemList) { foreach (var item in itemList) {
newPanel.ContentProperty.CollectionElements.Add(item.DesignItem); newPanel.ContentProperty.CollectionElements.Add(item.DesignItem);
if (newPanel.Component is Canvas) { if (newPanel.Component is Canvas) {
@ -418,184 +418,184 @@ namespace ICSharpCode.WpfDesign.Designer
} }
} }
PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents( PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents(
container, container,
new[] { newPanel }, new[] { newPanel },
new[] { new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round() }, new[] { new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round() },
PlacementType.AddItem PlacementType.AddItem
); );
operation.Commit(); operation.Commit();
changeGroup.Commit(); changeGroup.Commit();
_context.Services.Selection.SetSelectedComponents(new []{ newPanel }); _context.Services.Selection.SetSelectedComponents(new []{ newPanel });
} }
public static void ArrangeItems(IEnumerable<DesignItem> items, ArrangeDirection arrangeDirection) public static void ArrangeItems(IEnumerable<DesignItem> items, ArrangeDirection arrangeDirection)
{ {
var collection = items; var collection = items;
var _context = collection.First().Context as XamlDesignContext; var _context = collection.First().Context as XamlDesignContext;
var container = collection.First().Parent; var container = collection.First().Parent;
if (collection.Any(x => x.Parent != container)) if (collection.Any(x => x.Parent != container))
return; return;
var placement = container.Extensions.OfType<IPlacementBehavior>().FirstOrDefault(); var placement = container.Extensions.OfType<IPlacementBehavior>().FirstOrDefault();
if (placement == null) if (placement == null)
return; return;
var changeGroup = container.OpenGroup("Arrange Elements"); var changeGroup = container.OpenGroup("Arrange Elements");
List<ItemPos> itemList = new List<ItemPos>(); List<ItemPos> itemList = new List<ItemPos>();
foreach (var item in collection) foreach (var item in collection)
{ {
itemList.Add(GetItemPos(placement, item)); itemList.Add(GetItemPos(placement, item));
} }
var xmin = itemList.Min(x => x.Xmin); var xmin = itemList.Min(x => x.Xmin);
var xmax = itemList.Max(x => x.Xmax); var xmax = itemList.Max(x => x.Xmax);
var mpos = (xmax - xmin) / 2 + xmin; var mpos = (xmax - xmin) / 2 + xmin;
var ymin = itemList.Min(x => x.Ymin); var ymin = itemList.Min(x => x.Ymin);
var ymax = itemList.Max(x => x.Ymax); var ymax = itemList.Max(x => x.Ymax);
var ympos = (ymax - ymin) / 2 + ymin; var ympos = (ymax - ymin) / 2 + ymin;
foreach (var item in collection) foreach (var item in collection)
{ {
switch (arrangeDirection) switch (arrangeDirection)
{ {
case ArrangeDirection.Left: case ArrangeDirection.Left:
{ {
if (container.Component is Canvas) if (container.Component is Canvas)
{ {
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{ {
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(xmin); item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(xmin);
} }
else else
{ {
var pos = (double)((Panel)item.Parent.Component).ActualWidth - (xmin + (double) ((FrameworkElement) item.Component).ActualWidth); var pos = (double)((Panel)item.Parent.Component).ActualWidth - (xmin + (double) ((FrameworkElement) item.Component).ActualWidth);
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
} }
} }
else if (container.Component is Grid) else if (container.Component is Grid)
{ {
} }
} }
break; break;
case ArrangeDirection.HorizontalMiddle: case ArrangeDirection.HorizontalMiddle:
{ {
if (container.Component is Canvas) if (container.Component is Canvas)
{ {
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{ {
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(mpos - (((FrameworkElement)item.Component).ActualWidth) / 2); item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(mpos - (((FrameworkElement)item.Component).ActualWidth) / 2);
} }
else else
{ {
var pp = mpos - (((FrameworkElement) item.Component).ActualWidth)/2; var pp = mpos - (((FrameworkElement) item.Component).ActualWidth)/2;
var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth); var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth);
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
} }
} }
else if (container.Component is Grid) else if (container.Component is Grid)
{ {
} }
} }
break; break;
case ArrangeDirection.Right: case ArrangeDirection.Right:
{ {
if (container.Component is Canvas) if (container.Component is Canvas)
{ {
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{ {
var pos = xmax - (double)((FrameworkElement)item.Component).ActualWidth; var pos = xmax - (double)((FrameworkElement)item.Component).ActualWidth;
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(pos); item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(pos);
} }
else else
{ {
var pos = (double)((Panel)item.Parent.Component).ActualWidth - xmax; var pos = (double)((Panel)item.Parent.Component).ActualWidth - xmax;
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos); item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
} }
} }
else if (container.Component is Grid) else if (container.Component is Grid)
{ {
} }
} }
break; break;
case ArrangeDirection.Top: case ArrangeDirection.Top:
{ {
if (container.Component is Canvas) if (container.Component is Canvas)
{ {
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
{ {
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin); item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin);
} }
else else
{ {
var pos = (double)((Panel)item.Parent.Component).ActualHeight - (ymin + (double)((FrameworkElement)item.Component).ActualHeight); var pos = (double)((Panel)item.Parent.Component).ActualHeight - (ymin + (double)((FrameworkElement)item.Component).ActualHeight);
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos);
} }
} }
else if (container.Component is Grid) else if (container.Component is Grid)
{ {
} }
} }
break; break;
case ArrangeDirection.VerticalMiddle: case ArrangeDirection.VerticalMiddle:
{ {
if (container.Component is Canvas) if (container.Component is Canvas)
{ {
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
{ {
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ympos - (((FrameworkElement)item.Component).ActualHeight) / 2); item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ympos - (((FrameworkElement)item.Component).ActualHeight) / 2);
} }
else else
{ {
var pp = mpos - (((FrameworkElement)item.Component).ActualHeight) / 2; var pp = mpos - (((FrameworkElement)item.Component).ActualHeight) / 2;
var pos = (double)((Panel)item.Parent.Component).ActualHeight - pp - (((FrameworkElement)item.Component).ActualHeight); var pos = (double)((Panel)item.Parent.Component).ActualHeight - pp - (((FrameworkElement)item.Component).ActualHeight);
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos);
} }
} }
else if (container.Component is Grid) else if (container.Component is Grid)
{ {
} }
} }
break; break;
case ArrangeDirection.Bottom: case ArrangeDirection.Bottom:
{ {
if (container.Component is Canvas) if (container.Component is Canvas)
{ {
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
{ {
var pos = ymax - (double)((FrameworkElement)item.Component).ActualHeight; var pos = ymax - (double)((FrameworkElement)item.Component).ActualHeight;
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(pos); item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(pos);
} }
else else
{ {
var pos = (double)((Panel)item.Parent.Component).ActualHeight - ymax; var pos = (double)((Panel)item.Parent.Component).ActualHeight - ymax;
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos); item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos);
} }
} }
else if (container.Component is Grid) else if (container.Component is Grid)
{ {
} }
} }
break; break;
} }
} }
changeGroup.Commit(); changeGroup.Commit();
//_context.Services.Selection.SetSelectedComponents(null); //_context.Services.Selection.SetSelectedComponents(null);
//_context.Services.Selection.SetSelectedComponents(items.ToList()); //_context.Services.Selection.SetSelectedComponents(items.ToList());
} }
} }
} }

1616
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml

File diff suppressed because it is too large Load Diff

364
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs

@ -26,186 +26,186 @@ using ICSharpCode.WpfDesign.Designer.Xaml;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
{ {
/// <summary> /// <summary>
/// Interaktionslogik für FormatedTextEditor.xaml /// Interaktionslogik für FormatedTextEditor.xaml
/// </summary> /// </summary>
public partial class FormatedTextEditor public partial class FormatedTextEditor
{ {
private DesignItem designItem; private DesignItem designItem;
public FormatedTextEditor(DesignItem designItem) public FormatedTextEditor(DesignItem designItem)
{ {
InitializeComponent(); InitializeComponent();
this.designItem = designItem; this.designItem = designItem;
IEnumerable<Inline> inlines = null; IEnumerable<Inline> inlines = null;
var tb = ((TextBlock) designItem.Component); var tb = ((TextBlock) designItem.Component);
inlines = tb.Inlines.Select(x => CloneInline(x)).ToList(); inlines = tb.Inlines.Select(x => CloneInline(x)).ToList();
var paragraph = richTextBox.Document.Blocks.First() as Paragraph; var paragraph = richTextBox.Document.Blocks.First() as Paragraph;
paragraph.Inlines.AddRange(inlines); paragraph.Inlines.AddRange(inlines);
richTextBox.Document.Blocks.Add(paragraph); richTextBox.Document.Blocks.Add(paragraph);
richTextBox.Foreground = tb.Foreground; richTextBox.Foreground = tb.Foreground;
richTextBox.Background = tb.Background; richTextBox.Background = tb.Background;
} }
private void GetDesignItems(TextElementCollection<Block> blocks, List<DesignItem> list) private void GetDesignItems(TextElementCollection<Block> blocks, List<DesignItem> list)
{ {
bool first = true; bool first = true;
foreach (var block in blocks) foreach (var block in blocks)
{ {
if (block is Paragraph) if (block is Paragraph)
{ {
if (!first) if (!first)
{ {
list.Add(designItem.Services.Component.RegisterComponentForDesigner(new LineBreak())); list.Add(designItem.Services.Component.RegisterComponentForDesigner(new LineBreak()));
list.Add(designItem.Services.Component.RegisterComponentForDesigner(new LineBreak())); list.Add(designItem.Services.Component.RegisterComponentForDesigner(new LineBreak()));
} }
foreach (var inline in ((Paragraph) block).Inlines) foreach (var inline in ((Paragraph) block).Inlines)
{ {
list.Add(InlineToDesignItem(inline)); list.Add(InlineToDesignItem(inline));
} }
} }
else if (block is Section) else if (block is Section)
{ {
GetDesignItems(((Section)block).Blocks, list); GetDesignItems(((Section)block).Blocks, list);
} }
first = false; first = false;
} }
} }
private Inline CloneInline(Inline inline) private Inline CloneInline(Inline inline)
{ {
Inline retVal = null; Inline retVal = null;
if (inline is LineBreak) if (inline is LineBreak)
retVal = new LineBreak(); retVal = new LineBreak();
else if (inline is Span) else if (inline is Span)
retVal = new Span(); retVal = new Span();
else if (inline is Run) else if (inline is Run)
{ {
retVal = new Run(((Run) inline).Text); retVal = new Run(((Run) inline).Text);
} }
retVal.Background = inline.Background; retVal.Background = inline.Background;
retVal.Foreground = inline.Foreground; retVal.Foreground = inline.Foreground;
retVal.FontFamily = inline.FontFamily; retVal.FontFamily = inline.FontFamily;
retVal.FontSize = inline.FontSize; retVal.FontSize = inline.FontSize;
retVal.FontStretch = inline.FontStretch; retVal.FontStretch = inline.FontStretch;
retVal.FontStyle = inline.FontStyle; retVal.FontStyle = inline.FontStyle;
retVal.FontWeight = inline.FontWeight; retVal.FontWeight = inline.FontWeight;
retVal.TextEffects = inline.TextEffects; retVal.TextEffects = inline.TextEffects;
retVal.TextDecorations = inline.TextDecorations; retVal.TextDecorations = inline.TextDecorations;
return retVal; return retVal;
} }
private DesignItem InlineToDesignItem(Inline inline) private DesignItem InlineToDesignItem(Inline inline)
{ {
DesignItem d = d = designItem.Services.Component.RegisterComponentForDesigner(CloneInline(inline)); DesignItem d = d = designItem.Services.Component.RegisterComponentForDesigner(CloneInline(inline));
if (inline is Run) if (inline is Run)
{ {
var run = inline as Run; var run = inline as Run;
if (run.ReadLocalValue(Run.TextProperty) != DependencyProperty.UnsetValue) if (run.ReadLocalValue(Run.TextProperty) != DependencyProperty.UnsetValue)
{ {
d.Properties.GetProperty(Run.TextProperty).SetValue(run.Text); d.Properties.GetProperty(Run.TextProperty).SetValue(run.Text);
} }
} }
else if (inline is Span) else if (inline is Span)
{ } { }
else if (inline is LineBreak) else if (inline is LineBreak)
{ } { }
else else
{ {
return null; return null;
} }
if (inline.ReadLocalValue(TextElement.BackgroundProperty) != DependencyProperty.UnsetValue) if (inline.ReadLocalValue(TextElement.BackgroundProperty) != DependencyProperty.UnsetValue)
d.Properties.GetProperty(TextElement.BackgroundProperty).SetValue(inline.Background); d.Properties.GetProperty(TextElement.BackgroundProperty).SetValue(inline.Background);
if (inline.ReadLocalValue(TextElement.ForegroundProperty) != DependencyProperty.UnsetValue) if (inline.ReadLocalValue(TextElement.ForegroundProperty) != DependencyProperty.UnsetValue)
d.Properties.GetProperty(TextElement.ForegroundProperty).SetValue(inline.Foreground); d.Properties.GetProperty(TextElement.ForegroundProperty).SetValue(inline.Foreground);
if (inline.ReadLocalValue(TextElement.FontFamilyProperty) != DependencyProperty.UnsetValue) if (inline.ReadLocalValue(TextElement.FontFamilyProperty) != DependencyProperty.UnsetValue)
d.Properties.GetProperty(TextElement.FontFamilyProperty).SetValue(inline.FontFamily); d.Properties.GetProperty(TextElement.FontFamilyProperty).SetValue(inline.FontFamily);
if (inline.ReadLocalValue(TextElement.FontSizeProperty) != DependencyProperty.UnsetValue) if (inline.ReadLocalValue(TextElement.FontSizeProperty) != DependencyProperty.UnsetValue)
d.Properties.GetProperty(TextElement.FontSizeProperty).SetValue(inline.FontSize); d.Properties.GetProperty(TextElement.FontSizeProperty).SetValue(inline.FontSize);
if (inline.ReadLocalValue(TextElement.FontStretchProperty) != DependencyProperty.UnsetValue) if (inline.ReadLocalValue(TextElement.FontStretchProperty) != DependencyProperty.UnsetValue)
d.Properties.GetProperty(TextElement.FontStretchProperty).SetValue(inline.FontStretch); d.Properties.GetProperty(TextElement.FontStretchProperty).SetValue(inline.FontStretch);
if (inline.ReadLocalValue(TextElement.FontStyleProperty) != DependencyProperty.UnsetValue) if (inline.ReadLocalValue(TextElement.FontStyleProperty) != DependencyProperty.UnsetValue)
d.Properties.GetProperty(TextElement.FontStyleProperty).SetValue(inline.FontStyle); d.Properties.GetProperty(TextElement.FontStyleProperty).SetValue(inline.FontStyle);
if (inline.ReadLocalValue(TextElement.FontWeightProperty) != DependencyProperty.UnsetValue) if (inline.ReadLocalValue(TextElement.FontWeightProperty) != DependencyProperty.UnsetValue)
d.Properties.GetProperty(TextElement.FontWeightProperty).SetValue(inline.FontWeight); d.Properties.GetProperty(TextElement.FontWeightProperty).SetValue(inline.FontWeight);
if (inline.TextDecorations.Count > 0) if (inline.TextDecorations.Count > 0)
{ {
d.Properties.GetProperty("TextDecorations").SetValue(new TextDecorationCollection()); d.Properties.GetProperty("TextDecorations").SetValue(new TextDecorationCollection());
var tdColl = d.Properties.GetProperty("TextDecorations"); var tdColl = d.Properties.GetProperty("TextDecorations");
foreach (var td in inline.TextDecorations) foreach (var td in inline.TextDecorations)
{ {
var newTd = designItem.Services.Component.RegisterComponentForDesigner(new TextDecoration()); var newTd = designItem.Services.Component.RegisterComponentForDesigner(new TextDecoration());
if (inline.ReadLocalValue(TextDecoration.LocationProperty) != DependencyProperty.UnsetValue) if (inline.ReadLocalValue(TextDecoration.LocationProperty) != DependencyProperty.UnsetValue)
newTd.Properties.GetProperty(TextDecoration.LocationProperty).SetValue(td.Location); newTd.Properties.GetProperty(TextDecoration.LocationProperty).SetValue(td.Location);
if (inline.ReadLocalValue(TextDecoration.PenProperty) != DependencyProperty.UnsetValue) if (inline.ReadLocalValue(TextDecoration.PenProperty) != DependencyProperty.UnsetValue)
newTd.Properties.GetProperty(TextDecoration.PenProperty).SetValue(td.Pen); newTd.Properties.GetProperty(TextDecoration.PenProperty).SetValue(td.Pen);
tdColl.CollectionElements.Add(newTd); tdColl.CollectionElements.Add(newTd);
} }
} }
return d; return d;
} }
private void Ok_Click(object sender, RoutedEventArgs e) private void Ok_Click(object sender, RoutedEventArgs e)
{ {
var changeGroup = designItem.OpenGroup("Formated Text"); var changeGroup = designItem.OpenGroup("Formated Text");
designItem.Properties.GetProperty(TextBlock.TextProperty).Reset(); designItem.Properties.GetProperty(TextBlock.TextProperty).Reset();
var inlinesProperty = designItem.Properties.GetProperty("Inlines"); var inlinesProperty = designItem.Properties.GetProperty("Inlines");
inlinesProperty.CollectionElements.Clear(); inlinesProperty.CollectionElements.Clear();
var doc = richTextBox.Document; var doc = richTextBox.Document;
richTextBox.Document = new FlowDocument(); richTextBox.Document = new FlowDocument();
var inlines = new List<DesignItem>(); var inlines = new List<DesignItem>();
GetDesignItems(doc.Blocks, inlines); GetDesignItems(doc.Blocks, inlines);
foreach (var inline in inlines) foreach (var inline in inlines)
{ {
inlinesProperty.CollectionElements.Add(inline); inlinesProperty.CollectionElements.Add(inline);
} }
changeGroup.Commit(); changeGroup.Commit();
this.TryFindParent<Window>().Close(); this.TryFindParent<Window>().Close();
} }
private void Cancel_Click(object sender, RoutedEventArgs e) private void Cancel_Click(object sender, RoutedEventArgs e)
{ {
this.TryFindParent<Window>().Close(); this.TryFindParent<Window>().Close();
} }
private void StrikeThroughButton_Click(object sender, RoutedEventArgs e) private void StrikeThroughButton_Click(object sender, RoutedEventArgs e)
{ {
TextRange range = new TextRange(richTextBox.Selection.Start, richTextBox.Selection.End); TextRange range = new TextRange(richTextBox.Selection.Start, richTextBox.Selection.End);
TextDecorationCollection tdc = (TextDecorationCollection) richTextBox.Selection.GetPropertyValue(Inline.TextDecorationsProperty); TextDecorationCollection tdc = (TextDecorationCollection) richTextBox.Selection.GetPropertyValue(Inline.TextDecorationsProperty);
if (tdc == null || !tdc.Equals(TextDecorations.Strikethrough)) if (tdc == null || !tdc.Equals(TextDecorations.Strikethrough))
{ {
tdc = TextDecorations.Strikethrough; tdc = TextDecorations.Strikethrough;
} }
else else
{ {
tdc = null; tdc = null;
} }
range.ApplyPropertyValue(Inline.TextDecorationsProperty, tdc); range.ApplyPropertyValue(Inline.TextDecorationsProperty, tdc);
} }
} }
} }

112
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs

@ -84,60 +84,60 @@ namespace ICSharpCode.WpfDesign.Designer
} }
} }
public virtual string FormatedTextEditor public virtual string FormatedTextEditor
{ {
get get
{ {
return "Formated Text Editor"; return "Formated Text Editor";
} }
} }
public virtual string ArrangeLeft public virtual string ArrangeLeft
{ {
get get
{ {
return "Arrange Left"; return "Arrange Left";
} }
} }
public virtual string ArrangeHorizontalMiddle public virtual string ArrangeHorizontalMiddle
{ {
get get
{ {
return "Horizontal centered"; return "Horizontal centered";
} }
} }
public virtual string ArrangeRight public virtual string ArrangeRight
{ {
get get
{ {
return "Arrange Right"; return "Arrange Right";
} }
} }
public virtual string ArrangeTop public virtual string ArrangeTop
{ {
get get
{ {
return "Arrange Top"; return "Arrange Top";
} }
} }
public virtual string ArrangeVerticalMiddle public virtual string ArrangeVerticalMiddle
{ {
get get
{ {
return "Vertical centered"; return "Vertical centered";
} }
} }
public virtual string ArrangeBottom public virtual string ArrangeBottom
{ {
get get
{ {
return "Arrange Bottom"; return "Arrange Bottom";
} }
} }
} }
} }

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/PlacementTests.cs

@ -53,7 +53,6 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
} }
[Test] [Test]
[Ignore("Currently bounds calculated using visuals")]
public void MoveFixedWidthButton() public void MoveFixedWidthButton()
{ {
DesignItem button = CreateCanvasContext("<Button Width='100' Height='200'/>"); DesignItem button = CreateCanvasContext("<Button Width='100' Height='200'/>");
@ -135,7 +134,6 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
} }
[Test] [Test]
[Ignore("Bounds calculated using Visuals")]
public void AssertSizeForFixedSize() public void AssertSizeForFixedSize()
{ {
Assert.AreEqual(50,_buttonIsGridWithFixedSize.Properties[FrameworkElement.HeightProperty].ValueOnInstance); Assert.AreEqual(50,_buttonIsGridWithFixedSize.Properties[FrameworkElement.HeightProperty].ValueOnInstance);

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/MarkupExtensionTests.cs

@ -71,7 +71,6 @@ namespace ICSharpCode.WpfDesign.Tests.XamlDom
} }
[Test] [Test]
[Ignore]
public void Test7() public void Test7()
{ {
TestMarkupExtension("Background=\"{DynamicResource {x:Static SystemColors.ControlBrushKey}}\""); TestMarkupExtension("Background=\"{DynamicResource {x:Static SystemColors.ControlBrushKey}}\"");

53
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs

@ -22,9 +22,6 @@ using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Input;
using ICSharpCode.WpfDesign.Adorners;
using System.Windows.Media; using System.Windows.Media;
namespace ICSharpCode.WpfDesign namespace ICSharpCode.WpfDesign
@ -205,31 +202,31 @@ namespace ICSharpCode.WpfDesign
this.changeGroup = items[0].Context.OpenGroup(type.ToString(), items); this.changeGroup = items[0].Context.OpenGroup(type.ToString(), items);
} }
/// <summary> /// <summary>
/// The Size wich the Element really should have (even if its smaller Rendered (like emtpy Image!)) /// The Size wich the Element really should have (even if its smaller Rendered (like emtpy Image!))
/// </summary> /// </summary>
/// <param name="element"></param> /// <param name="element"></param>
/// <returns></returns> /// <returns></returns>
public static Size GetRealElementSize(UIElement element) public static Size GetRealElementSize(UIElement element)
{ {
var size = element.RenderSize; var size = element.RenderSize;
if (element is FrameworkElement && !double.IsNaN(((FrameworkElement)element).Width)) if (element is FrameworkElement && !double.IsNaN(((FrameworkElement)element).Width))
size.Width = ((FrameworkElement)element).Width; size.Width = ((FrameworkElement)element).Width;
if (element is FrameworkElement && !double.IsNaN(((FrameworkElement)element).Height)) if (element is FrameworkElement && !double.IsNaN(((FrameworkElement)element).Height))
size.Height = ((FrameworkElement)element).Height; size.Height = ((FrameworkElement)element).Height;
if (element is FrameworkElement && size.Width < ((FrameworkElement)element).MinWidth) if (element is FrameworkElement && size.Width < ((FrameworkElement)element).MinWidth)
size.Width = ((FrameworkElement)element).MinWidth; size.Width = ((FrameworkElement)element).MinWidth;
if (element is FrameworkElement && size.Height < ((FrameworkElement)element).MinHeight) if (element is FrameworkElement && size.Height < ((FrameworkElement)element).MinHeight)
size.Height = ((FrameworkElement)element).Height; size.Height = ((FrameworkElement)element).Height;
if (element is FrameworkElement && size.Width == 0) if (element is FrameworkElement && size.Width == 0)
size.Width = element.DesiredSize.Width; size.Width = element.DesiredSize.Width;
if (element is FrameworkElement && size.Height == 0) if (element is FrameworkElement && size.Height == 0)
size.Height = element.DesiredSize.Height; size.Height = element.DesiredSize.Height;
return size; return size;
} }
/// <summary> /// <summary>
/// Gets the placement behavior associated with the specified items. /// Gets the placement behavior associated with the specified items.

Loading…
Cancel
Save