Browse Source

Merge pull request #52 from jogibear9988/master

Fixes / Extensions for XAML Designer
pull/54/merge
Siegfried Oleg Pammer 12 years ago
parent
commit
645658cbc9
  1. 9
      samples/XamlDesigner/Document.cs
  2. 7
      samples/XamlDesigner/MainWindow.xaml
  3. 49
      samples/XamlDesigner/MyTypeFinder.cs
  4. 103
      samples/XamlDesigner/Toolbox.cs
  5. 13
      samples/XamlDesigner/ToolboxView.xaml
  6. 17
      samples/XamlDesigner/ToolboxView.xaml.cs
  7. 1
      samples/XamlDesigner/XamlDesigner.csproj
  8. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs
  9. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopTranslations.cs
  10. 57
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/ThumbnailViewPad.cs
  11. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs
  12. 66
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs
  13. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs
  14. 316
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj
  15. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.addin
  16. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Configuration/AssemblyInfo.cs
  17. 218
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/CanvasPositionHandle.cs
  18. 82
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ClearableTextBox.cs
  19. 26
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ContainerDragHandle.cs
  20. 296
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
  21. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GrayOutDesignerExceptActiveArea.cs
  22. 101
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/InfoTextEnterArea.cs
  23. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/MarginHandle.cs
  24. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs
  25. 227
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs
  26. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/RenderTransformOriginThumb.cs
  27. 35
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/RotateThumb.cs
  28. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ZoomControl.cs
  29. 113
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs
  30. 85
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  31. 75
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs
  32. 52
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml
  33. 64
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForInvisibleControl.cs
  34. 56
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
  35. 77
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPositionExtension.cs
  36. 41
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs
  37. 48
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs
  38. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs
  39. 26
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelInstanceFactory.cs
  40. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelMove.cs
  41. 128
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs
  42. 88
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RenderTransformOriginExtension.cs
  43. 163
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs
  44. 176
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs
  45. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs
  46. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandle.cs
  47. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Raster.png
  48. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Snapline.png
  49. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/events.png
  50. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/eye_watch.png
  51. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/group.png
  52. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/group2.png
  53. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/properties.png
  54. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/rotate.cur
  55. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/sort.png
  56. 65
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  57. 34
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/Outline.xaml
  58. 33
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs
  59. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineView.xaml
  60. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/GradientSlider.xaml.cs
  61. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyContextMenu.xaml
  62. 624
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs
  63. 26
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGridView.cs
  64. 578
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGridView.xaml
  65. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs
  66. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs
  67. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/SelectionService.cs
  68. 155
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs
  69. 43
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.xaml
  70. 30
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs
  71. 43
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  72. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs
  73. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs
  74. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs
  75. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlEditOperations.cs
  76. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/themes/generic.xaml
  77. 17
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/EditOperationTests.cs
  78. 27
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/OutlineView/InsertTests.cs
  79. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
  80. 113
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/DesignTimeProperties.cs
  81. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupCompatibilityProperties.cs
  82. 186
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj
  83. 18
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlConstants.cs
  84. 131
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs
  85. 37
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs
  86. 59
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  87. 42
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  88. 80
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs
  89. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeResolverProvider.cs
  90. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Adorners/AdornerPanel.cs
  91. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs
  92. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs
  93. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementInformation.cs
  94. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs
  95. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementType.cs
  96. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/Editors/ComboBoxEditor.xaml
  97. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs
  98. 103
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/UIHelpers.cs
  99. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj

9
samples/XamlDesigner/Document.cs

@ -206,7 +206,14 @@ namespace ICSharpCode.XamlDesigner @@ -206,7 +206,14 @@ namespace ICSharpCode.XamlDesigner
{
OutlineRoot = null;
using (var xmlReader = XmlReader.Create(new StringReader(Text))) {
DesignSurface.LoadDesigner(xmlReader, null);
XamlLoadSettings settings = new XamlLoadSettings();
foreach (var assNode in Toolbox.Instance.AssemblyNodes)
{
settings.DesignerAssemblies.Add(assNode.Assembly);
}
settings.TypeFinder = MyTypeFinder.Instance;
DesignSurface.LoadDesigner(xmlReader, settings);
}
if (DesignContext.RootItem != null) {
OutlineRoot = OutlineNode.Create(DesignContext.RootItem);

7
samples/XamlDesigner/MainWindow.xaml

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<Window x:Class="ICSharpCode.XamlDesigner.MainWindow"
<Window x:Class="ICSharpCode.XamlDesigner.MainWindow"
x:Name="root"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@ -112,6 +112,11 @@ @@ -112,6 +112,11 @@
</AvalonDock:DockableContent>
</AvalonDock:DockablePane>
<AvalonDock:DockablePane>
<AvalonDock:DockableContent x:Name="content5" Title="Thumbnail">
<sd:ThumbnailView x:Name="uxThumbnailView" DesignSurface="{Binding DataContext.CurrentDocument.DesignSurface, ElementName=root, FallbackValue={x:Null}}" />
</AvalonDock:DockableContent>
</AvalonDock:DockablePane>
</AvalonDock:ResizingPanel>
</AvalonDock:DockingManager>
</DockPanel>

49
samples/XamlDesigner/MyTypeFinder.cs

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.XamlDesigner
{
public class MyTypeFinder : XamlTypeFinder
{
public override Assembly LoadAssembly(string name)
{
foreach (var assemblyNode in Toolbox.Instance.AssemblyNodes)
{
if (assemblyNode.Name == name)
return assemblyNode.Assembly;
}
return null;
}
public override XamlTypeFinder Clone()
{
return _instance;
}
private static object lockObj = new object();
private static MyTypeFinder _instance;
public static MyTypeFinder Instance
{
get
{
lock (lockObj)
{
if (_instance == null)
{
_instance = new MyTypeFinder();
_instance.ImportFrom(CreateWpfTypeFinder());
}
}
return _instance;
}
}
}
}

103
samples/XamlDesigner/Toolbox.cs

@ -14,45 +14,47 @@ namespace ICSharpCode.XamlDesigner @@ -14,45 +14,47 @@ namespace ICSharpCode.XamlDesigner
public class Toolbox
{
public Toolbox()
{
AssemblyNodes = new ObservableCollection<AssemblyNode>();
{
AssemblyNodes = new ObservableCollection<AssemblyNode>();
LoadSettings();
}
}
public static Toolbox Instance = new Toolbox();
public ObservableCollection<AssemblyNode> AssemblyNodes { get; private set; }
public ObservableCollection<AssemblyNode> AssemblyNodes { get; private set; }
public void AddAssembly(string path)
{
{
AddAssembly(path, true);
}
void AddAssembly(string path, bool updateSettings)
{
var assembly = Assembly.LoadFile(path);
var node = new AssemblyNode();
node.Assembly = assembly;
node.Path = path;
foreach (var t in assembly.GetExportedTypes()) {
if (IsControl(t) && Metadata.IsPopularControl(t)) {
node.Controls.Add(new ControlNode() { Type = t });
}
}
void AddAssembly(string path, bool updateSettings)
{
var assembly = Assembly.LoadFile(path);
MyTypeFinder.Instance.RegisterAssembly(assembly);
var node = new AssemblyNode();
node.Assembly = assembly;
node.Path = path;
foreach (var t in assembly.GetExportedTypes()) {
if (IsControl(t) /* && Metadata.IsPopularControl(t) */) {
node.Controls.Add(new ControlNode() { Type = t });
}
}
node.Controls.Sort(delegate(ControlNode c1, ControlNode c2) {
return c1.Name.CompareTo(c2.Name);
});
node.Controls.Sort(delegate(ControlNode c1, ControlNode c2) {
return c1.Name.CompareTo(c2.Name);
});
AssemblyNodes.Add(node);
AssemblyNodes.Add(node);
if (updateSettings) {
if (Settings.Default.AssemblyList == null) {
Settings.Default.AssemblyList = new StringCollection();
}
}
Settings.Default.AssemblyList.Add(path);
}
}
}
public void Remove(AssemblyNode node)
{
@ -61,42 +63,47 @@ namespace ICSharpCode.XamlDesigner @@ -61,42 +63,47 @@ namespace ICSharpCode.XamlDesigner
}
public void LoadSettings()
{
{
if (Settings.Default.AssemblyList != null) {
foreach (var path in Settings.Default.AssemblyList) {
AddAssembly(Environment.ExpandEnvironmentVariables(path), false);
try
{
AddAssembly(Environment.ExpandEnvironmentVariables(path), false);
}
catch (Exception ex)
{ }
}
}
}
static bool IsControl(Type t)
{
return !t.IsAbstract && !t.IsGenericTypeDefinition && t.IsSubclassOf(typeof(FrameworkElement));
}
static bool IsControl(Type t)
{
return !t.IsAbstract && !t.IsGenericTypeDefinition && t.IsSubclassOf(typeof(FrameworkElement));
}
}
public class AssemblyNode
{
public AssemblyNode()
{
Controls = new List<ControlNode>();
}
{
public AssemblyNode()
{
Controls = new List<ControlNode>();
}
public Assembly Assembly { get; set; }
public List<ControlNode> Controls { get; private set; }
public string Path { get; set; }
public Assembly Assembly { get; set; }
public List<ControlNode> Controls { get; private set; }
public string Path { get; set; }
public string Name {
get { return Assembly.GetName().Name; }
}
}
public string Name {
get { return Assembly.GetName().Name; }
}
}
public class ControlNode
{
public Type Type { get; set; }
public class ControlNode
{
public Type Type { get; set; }
public string Name {
get { return Type.Name; }
}
}
public string Name {
get { return Type.Name; }
}
}
}

13
samples/XamlDesigner/ToolboxView.xaml

@ -3,18 +3,23 @@ @@ -3,18 +3,23 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Outline="clr-namespace:ICSharpCode.WpfDesign.Designer.OutlineView;assembly=ICSharpCode.WpfDesign.Designer"
xmlns:Default="clr-namespace:ICSharpCode.XamlDesigner">
<UserControl.ContextMenu>
<ContextMenu>
<MenuItem Header="Browse..." Click="BrowseForAssemblies_OnClick"></MenuItem>
</ContextMenu>
</UserControl.ContextMenu>
<UserControl.Resources>
<HierarchicalDataTemplate DataType="{x:Type Default:AssemblyNode}"
ItemsSource="{Binding Controls}">
ItemsSource="{Binding Controls}">
<Outline:IconItem Icon="Images/Reference.png"
Text="{Binding Name}"
ToolTip="{Binding Path}" />
Text="{Binding Name}"
ToolTip="{Binding Path}" />
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type Default:ControlNode}">
<Outline:IconItem Icon="Images/Tag.png"
Text="{Binding Type.Name}" />
Text="{Binding Type.Name}" />
</DataTemplate>
</UserControl.Resources>

17
samples/XamlDesigner/ToolboxView.xaml.cs

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
using System.IO;
using ICSharpCode.WpfDesign.Designer.OutlineView;
using System;
using System.Collections.Generic;
@ -16,6 +17,7 @@ using System.Windows.Media.Imaging; @@ -16,6 +17,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Designer.Services;
using Microsoft.Win32;
namespace ICSharpCode.XamlDesigner
{
@ -73,5 +75,20 @@ namespace ICSharpCode.XamlDesigner @@ -73,5 +75,20 @@ namespace ICSharpCode.XamlDesigner
Toolbox.Instance.Remove(node);
}
}
private void BrowseForAssemblies_OnClick(object sender, RoutedEventArgs e)
{
var dlg = new OpenFileDialog();
dlg.Filter = "Assemblies (*.dll)|*.dll";
dlg.Multiselect = true;
dlg.CheckFileExists = true;
if (dlg.ShowDialog().Value)
{
foreach (var fileName in dlg.FileNames)
{
Toolbox.Instance.AddAssembly(fileName);
}
}
}
}
}

1
samples/XamlDesigner/XamlDesigner.csproj

@ -129,6 +129,7 @@ @@ -129,6 +129,7 @@
</Compile>
<Compile Include="ExtensionMethods.cs" />
<Compile Include="MainWindow_Commands.cs" />
<Compile Include="MyTypeFinder.cs" />
<Compile Include="Shell.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>

21
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/MyTypeFinder.cs

@ -21,6 +21,27 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -21,6 +21,27 @@ namespace ICSharpCode.WpfDesign.AddIn
MyTypeFinder f = new MyTypeFinder();
f.file = file;
f.ImportFrom(CreateWpfTypeFinder());
var pc = MyTypeFinder.GetProjectContent(file);
foreach (var referencedProjectContent in pc.ThreadSafeGetReferencedContents()) {
try{
string fileName = null;
if (referencedProjectContent is ParseProjectContent)
{
var prj = ((ParseProjectContent)referencedProjectContent).Project as AbstractProject;
if (prj != null)
fileName = prj.OutputAssemblyFullPath;
}
else if (referencedProjectContent is ReflectionProjectContent)
{
fileName = ((ReflectionProjectContent) referencedProjectContent).AssemblyLocation;
}
var assembly = Assembly.LoadFrom(fileName);
f.RegisterAssembly(assembly);
}
catch (Exception ex)
{}
}
return f;
}

23
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/SharpDevelopTranslations.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using ICSharpCode.Core;
using System;
using ICSharpCode.WpfDesign.Designer;
namespace ICSharpCode.WpfDesign.AddIn
{
/// <summary>
/// Description of SharpDevelopTranslations.
/// </summary>
public class SharpDevelopTranslations : Translations
{
public override string PressAltText {
get { return StringParser.Parse("${res:AddIns.WpfDesign.AddIn.PressAltText}"); }
}
public static void Init() {
Instance = new SharpDevelopTranslations();
}
}
}

57
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/ThumbnailViewPad.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows;
using System.Windows.Controls;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.WpfDesign.Designer.ThumbnailView;
namespace ICSharpCode.WpfDesign.AddIn
{
public class ThumbnailViewPad : AbstractPadContent
{
ContentPresenter contentControl = new ContentPresenter();
ThumbnailView thumbnailView = new ThumbnailView();
TextBlock notAvailableTextBlock = new TextBlock {
Text = StringParser.Parse("${res:ICSharpCode.SharpDevelop.Gui.OutlinePad.NotAvailable}"),
TextWrapping = TextWrapping.Wrap
};
public ThumbnailViewPad()
{
WorkbenchSingleton.Workbench.ActiveViewContentChanged += WorkbenchActiveViewContentChanged;
WorkbenchActiveViewContentChanged(null, null);
}
void WorkbenchActiveViewContentChanged(object sender, EventArgs e)
{
WpfViewContent wpfView = WorkbenchSingleton.Workbench.ActiveViewContent as WpfViewContent;
if (wpfView != null)
{
thumbnailView.DesignSurface = wpfView.DesignSurface;
contentControl.SetContent(thumbnailView);
}
else
{
contentControl.SetContent(notAvailableTextBlock);
}
}
/// <summary>
/// The <see cref="System.Windows.Forms.Control"/> representing the pad
/// </summary>
public override object Control {
get {
return contentControl;
}
}
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfDisplayBinding.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -51,7 +51,7 @@ namespace ICSharpCode.WpfDesign.AddIn
r.XmlResolver = null;
r.WhitespaceHandling = WhitespaceHandling.None;
while (r.NodeType != XmlNodeType.Element && r.Read());
if (r.LocalName == "ResourceDictionary" || r.LocalName == "Activity")
if (r.LocalName == "ResourceDictionary" || r.LocalName == "Application" || r.LocalName == "Activity")
return false;
} catch (XmlException) {
return true;

66
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfToolbox.cs

@ -2,11 +2,18 @@ @@ -2,11 +2,18 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Windows;
using System.Windows.Forms;
using System.Linq;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Widgets.SideBar;
using WPF = System.Windows.Controls;
@ -48,6 +55,65 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -48,6 +55,65 @@ namespace ICSharpCode.WpfDesign.AddIn
sideBar.ActiveTab = sideTab;
}
static bool IsControl(Type t)
{
return !t.IsAbstract && !t.IsGenericTypeDefinition && t.IsSubclassOf(typeof(FrameworkElement));
}
private static HashSet<string> addedAssemblys = new HashSet<string>();
public void AddProjectDlls(OpenedFile file)
{
var pc = MyTypeFinder.GetProjectContent(file);
foreach (var referencedProjectContent in pc.ThreadSafeGetReferencedContents())
{
string f = null;
if (referencedProjectContent is ParseProjectContent)
{
var prj = ((ParseProjectContent)referencedProjectContent).Project as AbstractProject;
if (prj != null)
f = prj.OutputAssemblyFullPath;
}
else if (referencedProjectContent is ReflectionProjectContent)
{
f = ((ReflectionProjectContent) referencedProjectContent).AssemblyLocation;
}
if (f != null && !addedAssemblys.Contains(f))
{
try
{
var assembly = Assembly.LoadFrom(f);
SideTab sideTab = new SideTab(sideBar, assembly.FullName.Split(new[] {','})[0]);
sideTab.DisplayName = StringParser.Parse(sideTab.Name);
sideTab.CanBeDeleted = false;
sideTab.ChoosedItemChanged += OnChoosedItemChanged;
sideTab.Items.Add(new WpfSideTabItem());
foreach (var t in assembly.GetExportedTypes())
{
if (IsControl(t))
{
sideTab.Items.Add(new WpfSideTabItem(t));
}
}
if (sideTab.Items.Count > 1)
sideBar.Tabs.Add(sideTab);
addedAssemblys.Add(f);
}
catch (Exception ex)
{
WpfViewContent.DllLoadErrors.Add(
new Task(new BuildError(f, ex.Message)));
}
}
}
}
void OnChoosedItemChanged(object sender, EventArgs e)
{
if (toolService != null) {

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/Src/WpfViewContent.cs

@ -18,6 +18,7 @@ using ICSharpCode.SharpDevelop; @@ -18,6 +18,7 @@ using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Refactoring;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.OutlineView;
@ -34,11 +35,23 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -34,11 +35,23 @@ namespace ICSharpCode.WpfDesign.AddIn
{
public WpfViewContent(OpenedFile file) : base(file)
{
SharpDevelopTranslations.Init();
BasicMetadata.Register();
WpfToolbox.Instance.AddProjectDlls(file);
ProjectService.ProjectItemAdded += ProjectService_ProjectItemAdded;
this.TabPageText = "${res:FormsDesigner.DesignTabPages.DesignTabPage}";
this.IsActiveViewContentChanged += OnIsActiveViewContentChanged;
}
void ProjectService_ProjectItemAdded(object sender, ProjectItemEventArgs e)
{
if (e.ProjectItem is ReferenceProjectItem)
WpfToolbox.Instance.AddProjectDlls(this.Files[0]);
}
static WpfViewContent()
{
@ -131,6 +144,7 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -131,6 +144,7 @@ namespace ICSharpCode.WpfDesign.AddIn
}
}
public static List<Task> DllLoadErrors = new List<Task>();
void UpdateTasks(XamlErrorService xamlErrorService)
{
Debug.Assert(xamlErrorService != null);
@ -141,11 +155,13 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -141,11 +155,13 @@ namespace ICSharpCode.WpfDesign.AddIn
tasks.Clear();
foreach (XamlError error in xamlErrorService.Errors) {
var task = new Task(PrimaryFile.FileName, error.Message, error.Column - 1, error.Line - 1, TaskType.Error);
var task = new Task(PrimaryFile.FileName, error.Message, error.Column - 1, error.Line, TaskType.Error);
tasks.Add(task);
TaskService.Add(task);
}
TaskService.AddRange(DllLoadErrors);
if (xamlErrorService.Errors.Count != 0) {
WorkbenchSingleton.Workbench.GetPad(typeof(ErrorListPad)).BringPadToFront();
}
@ -222,6 +238,8 @@ namespace ICSharpCode.WpfDesign.AddIn @@ -222,6 +238,8 @@ namespace ICSharpCode.WpfDesign.AddIn
public override void Dispose()
{
ProjectService.ProjectItemAdded -= ProjectService_ProjectItemAdded;
propertyContainer.Clear();
base.Dispose();
}

316
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.AddIn.csproj

@ -1,160 +1,158 @@ @@ -1,160 +1,158 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<ProjectGuid>{9A9D6FD4-6A2E-455D-ACC3-DDA775FE9865}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.WpfDesign.AddIn</RootNamespace>
<AssemblyName>ICSharpCode.WpfDesign.AddIn</AssemblyName>
<OutputPath>..\..\..\..\..\AddIns\DisplayBindings\WpfDesign\</OutputPath>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<Optimize>False</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Icons.32x32.Error.png" />
<None Include="WpfDesign.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\AbstractEventHandlerService.cs" />
<Compile Include="Src\Commands\CutCopyPaste.cs" />
<Compile Include="Src\Commands\Pads.cs" />
<Compile Include="Src\Commands\Remove.cs" />
<Compile Include="Src\Commands\UndoRedo.cs" />
<Compile Include="Src\Commands\ViewXaml.cs" />
<Compile Include="Src\CSharpEventHandlerService.cs" />
<Compile Include="Src\FileUriContext.cs" />
<Compile Include="Src\IdeChooseClassService.cs" />
<Compile Include="Src\ImageSourceEditor\ChooseImageDialog.xaml.cs">
<DependentUpon>ChooseImageDialog.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\ImageSourceEditor\ImageSourceEditor.xaml.cs">
<DependentUpon>ImageSourceEditor.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\MyTypeFinder.cs" />
<Compile Include="Src\ObjectEditor.xaml.cs">
<DependentUpon>ObjectEditor.xaml</DependentUpon>
</Compile>
<Compile Include="Src\OutlineViewPad.cs" />
<Compile Include="Src\ProjectTools.cs" />
<Compile Include="Src\PropertyDescriptionService.cs" />
<Compile Include="Src\WpfAndWinFormsTopLevelWindowService.cs" />
<Compile Include="Src\WpfDisplayBinding.cs" />
<Compile Include="Src\WpfDocumentError.xaml.cs">
<DependentUpon>WpfDocumentError.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\WpfSideTabItem.cs" />
<Compile Include="Src\WpfToolbox.cs" />
<Compile Include="Src\WpfViewContent.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="Src\WpfDocumentError.xaml" />
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj">
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project>
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
<Name>ICSharpCode.Core.Presentation</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.WinForms\ICSharpCode.Core.WinForms.csproj">
<Project>{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288}</Project>
<Name>ICSharpCode.Core.WinForms</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj">
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project>
<Name>ICSharpCode.SharpDevelop.Dom</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
<Name>ICSharpCode.SharpDevelop.Widgets</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\FormsDesigner\Project\FormsDesigner.csproj">
<Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project>
<Name>FormsDesigner</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\WpfDesign.Designer\Project\WpfDesign.Designer.csproj">
<Project>{78CC29AC-CC79-4355-B1F2-97936DF198AC}</Project>
<Name>WpfDesign.Designer</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\WpfDesign.XamlDom\Project\WpfDesign.XamlDom.csproj">
<Project>{88DA149F-21B2-48AB-82C4-28FB6BDFD783}</Project>
<Name>WpfDesign.XamlDom</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\WpfDesign\Project\WpfDesign.csproj">
<Project>{66A378A1-E9F4-4AD5-8946-D0EC06C2902F}</Project>
<Name>WpfDesign</Name>
<Private>False</Private>
</ProjectReference>
<Page Include="Src\ImageSourceEditor\ChooseImageDialog.xaml" />
<Page Include="Src\ImageSourceEditor\ImageSourceEditor.xaml" />
<Page Include="Src\ObjectEditor.xaml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Images" />
<Folder Include="Src\ImageSourceEditor" />
<Folder Include="Src\Commands" />
</ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<ProjectGuid>{9A9D6FD4-6A2E-455D-ACC3-DDA775FE9865}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.WpfDesign.AddIn</RootNamespace>
<AssemblyName>ICSharpCode.WpfDesign.AddIn</AssemblyName>
<OutputPath>..\..\..\..\..\AddIns\DisplayBindings\WpfDesign\</OutputPath>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<Optimize>False</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Icons.32x32.Error.png" />
<None Include="WpfDesign.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\AbstractEventHandlerService.cs" />
<Compile Include="Src\Commands\CutCopyPaste.cs" />
<Compile Include="Src\Commands\Pads.cs" />
<Compile Include="Src\Commands\Remove.cs" />
<Compile Include="Src\Commands\UndoRedo.cs" />
<Compile Include="Src\Commands\ViewXaml.cs" />
<Compile Include="Src\SharpDevelopTranslations.cs" />
<Compile Include="Src\ThumbnailViewPad.cs" />
<Compile Include="Src\CSharpEventHandlerService.cs" />
<Compile Include="Src\FileUriContext.cs" />
<Compile Include="Src\IdeChooseClassService.cs" />
<Compile Include="Src\ImageSourceEditor\ChooseImageDialog.xaml.cs">
<DependentUpon>ChooseImageDialog.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\ImageSourceEditor\ImageSourceEditor.xaml.cs">
<DependentUpon>ImageSourceEditor.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\MyTypeFinder.cs" />
<Compile Include="Src\ObjectEditor.xaml.cs">
<DependentUpon>ObjectEditor.xaml</DependentUpon>
</Compile>
<Compile Include="Src\OutlineViewPad.cs" />
<Compile Include="Src\ProjectTools.cs" />
<Compile Include="Src\PropertyDescriptionService.cs" />
<Compile Include="Src\WpfAndWinFormsTopLevelWindowService.cs" />
<Compile Include="Src\WpfDisplayBinding.cs" />
<Compile Include="Src\WpfDocumentError.xaml.cs">
<DependentUpon>WpfDocumentError.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\WpfSideTabItem.cs" />
<Compile Include="Src\WpfToolbox.cs" />
<Compile Include="Src\WpfViewContent.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="Src\WpfDocumentError.xaml" />
<ProjectReference Include="..\..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
<Project>{2748AD25-9C63-4E12-877B-4DCE96FBED54}</Project>
<Name>ICSharpCode.SharpDevelop</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\Core\Project\ICSharpCode.Core.csproj">
<Project>{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}</Project>
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
<Name>ICSharpCode.Core.Presentation</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.Core.WinForms\ICSharpCode.Core.WinForms.csproj">
<Project>{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288}</Project>
<Name>ICSharpCode.Core.WinForms</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj">
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project>
<Name>ICSharpCode.SharpDevelop.Dom</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
<Name>ICSharpCode.SharpDevelop.Widgets</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\FormsDesigner\Project\FormsDesigner.csproj">
<Project>{7D7E92DF-ACEB-4B69-92C8-8AC7A703CD57}</Project>
<Name>FormsDesigner</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\WpfDesign.Designer\Project\WpfDesign.Designer.csproj">
<Project>{78CC29AC-CC79-4355-B1F2-97936DF198AC}</Project>
<Name>WpfDesign.Designer</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\WpfDesign.XamlDom\Project\WpfDesign.XamlDom.csproj">
<Project>{88DA149F-21B2-48AB-82C4-28FB6BDFD783}</Project>
<Name>WpfDesign.XamlDom</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\WpfDesign\Project\WpfDesign.csproj">
<Project>{66A378A1-E9F4-4AD5-8946-D0EC06C2902F}</Project>
<Name>WpfDesign</Name>
<Private>False</Private>
</ProjectReference>
<Page Include="Src\ImageSourceEditor\ChooseImageDialog.xaml" />
<Page Include="Src\ImageSourceEditor\ImageSourceEditor.xaml" />
<Page Include="Src\ObjectEditor.xaml" />
</ItemGroup>
<ItemGroup />
</Project>

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.AddIn/WpfDesign.addin

@ -23,6 +23,14 @@ @@ -23,6 +23,14 @@
title = "WPF designer"/>-->
<DisplayBinding id="WPFDesigner" type="Secondary" class="ICSharpCode.WpfDesign.AddIn.WpfSecondaryDisplayBinding" fileNamePattern="\.xaml$" />
</Path>
<Path name = "/SharpDevelop/Workbench/Pads">
<Pad id = "ThumbnailViewPad"
category = "Main"
title = "${res:ICSharpCode.WpfDesign.AddIn.ThumbnailViewPad}"
icon = "PadIcons.Toolbar"
class = "ICSharpCode.WpfDesign.AddIn.ThumbnailViewPad"
defaultPosition = "Right, Hidden" />
</Path>
<!--
<Path name = "/SharpDevelop/Workbench/Pads">
<Pad id = "OutlineViewPad"

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Configuration/AssemblyInfo.cs

@ -50,3 +50,4 @@ using System.Windows.Markup; @@ -50,3 +50,4 @@ using System.Windows.Markup;
[assembly: XmlnsDefinition("http://sharpdevelop.net", "ICSharpCode.WpfDesign.Designer.Controls")]
[assembly: XmlnsDefinition("http://sharpdevelop.net", "ICSharpCode.WpfDesign.Designer.PropertyGrid")]
[assembly: XmlnsDefinition("http://sharpdevelop.net", "ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors")]
[assembly: XmlnsDefinition("http://sharpdevelop.net", "ICSharpCode.WpfDesign.Designer.ThumbnailView")]

218
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/CanvasPositionHandle.cs

@ -0,0 +1,218 @@ @@ -0,0 +1,218 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Input;
using System.Globalization;
using System.ComponentModel;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Adorner that displays the margin of a control in a Grid.
/// </summary>
public class CanvasPositionHandle : MarginHandle
{
static CanvasPositionHandle()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CanvasPositionHandle), new FrameworkPropertyMetadata(typeof(CanvasPositionHandle)));
HandleLengthOffset=2;
}
private Path line1;
private Path line2;
public override void OnApplyTemplate()
{
line1 = GetTemplateChild("line1") as Path;
line2 = GetTemplateChild("line2") as Path;
base.OnApplyTemplate();
}
readonly Canvas canvas;
readonly DesignItem adornedControlItem;
readonly AdornerPanel adornerPanel;
readonly HandleOrientation orientation;
readonly FrameworkElement adornedControl;
/// <summary> This grid contains the handle line and the endarrow.</summary>
Grid lineArrow;
private DependencyPropertyDescriptor leftDescriptor;
private DependencyPropertyDescriptor rightDescriptor;
private DependencyPropertyDescriptor topDescriptor;
private DependencyPropertyDescriptor bottomDescriptor;
private DependencyPropertyDescriptor widthDescriptor;
private DependencyPropertyDescriptor heightDescriptor;
public CanvasPositionHandle(DesignItem adornedControlItem, AdornerPanel adornerPanel, HandleOrientation orientation)
{
Debug.Assert(adornedControlItem != null);
this.adornedControlItem = adornedControlItem;
this.adornerPanel = adornerPanel;
this.orientation = orientation;
Angle = (double) orientation;
canvas = (Canvas) adornedControlItem.Parent.Component;
adornedControl = (FrameworkElement) adornedControlItem.Component;
Stub = new MarginStub(this);
ShouldBeVisible = true;
leftDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.LeftProperty,
adornedControlItem.Component.GetType());
leftDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
rightDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.RightProperty,
adornedControlItem.Component.GetType());
rightDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
topDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.TopProperty,
adornedControlItem.Component.GetType());
topDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
bottomDescriptor = DependencyPropertyDescriptor.FromProperty(Canvas.BottomProperty,
adornedControlItem.Component.GetType());
bottomDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
widthDescriptor = DependencyPropertyDescriptor.FromProperty(Control.WidthProperty,
adornedControlItem.Component.GetType());
widthDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
heightDescriptor = DependencyPropertyDescriptor.FromProperty(Control.WidthProperty,
adornedControlItem.Component.GetType());
heightDescriptor.AddValueChanged(adornedControl, OnPropertyChanged);
BindAndPlaceHandle();
}
void OnPropertyChanged(object sender, EventArgs e)
{
BindAndPlaceHandle();
}
/// <summary>
/// Gets/Sets the angle by which the Canvas display has to be rotated
/// </summary>
public override double TextTransform
{
get
{
if ((double)orientation == 90 || (double)orientation == 180)
return 180;
if ((double)orientation == 270)
return 0;
return (double)orientation;
}
set { }
}
/// <summary>
/// Binds the <see cref="HandleLength"/> to the margin and place the handles.
/// </summary>
void BindAndPlaceHandle()
{
if (!adornerPanel.Children.Contains(this))
adornerPanel.Children.Add(this);
if (!adornerPanel.Children.Contains(Stub))
adornerPanel.Children.Add(Stub);
RelativePlacement placement=new RelativePlacement();
switch (orientation)
{
case HandleOrientation.Left:
{
var wr = (double) leftDescriptor.GetValue(adornedControl);
if (double.IsNaN(wr))
{
wr = (double) rightDescriptor.GetValue(adornedControl);
wr = canvas.ActualWidth - (adornedControl.ActualWidth + wr);
}
else
{
if (line1 != null)
{
line1.StrokeDashArray.Clear();
line2.StrokeDashArray.Clear();
}
}
this.HandleLength = wr;
placement = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Center);
placement.XOffset = -HandleLengthOffset;
break;
}
case HandleOrientation.Top:
{
var wr = (double)topDescriptor.GetValue(adornedControl);
if (double.IsNaN(wr))
{
wr = (double)bottomDescriptor.GetValue(adornedControl);
wr = canvas.ActualHeight - (adornedControl.ActualHeight + wr);
}
else
{
if (line1 != null)
{
line1.StrokeDashArray.Clear();
line2.StrokeDashArray.Clear();
}
}
this.HandleLength = wr;
placement = new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Top);
placement.YOffset = -HandleLengthOffset;
break;
}
case HandleOrientation.Right:
{
var wr = (double) rightDescriptor.GetValue(adornedControl);
if (double.IsNaN(wr))
{
wr = (double) leftDescriptor.GetValue(adornedControl);
wr = canvas.ActualWidth - (adornedControl.ActualWidth + wr);
}
else
{
if (line1 != null)
{
line1.StrokeDashArray.Clear();
line2.StrokeDashArray.Clear();
}
}
this.HandleLength = wr;
placement = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Center);
placement.XOffset = HandleLengthOffset;
break;
}
case HandleOrientation.Bottom:
{
var wr = (double)bottomDescriptor.GetValue(adornedControl);
if (double.IsNaN(wr))
{
wr = (double)topDescriptor.GetValue(adornedControl);
wr = canvas.ActualHeight - (adornedControl.ActualHeight + wr);
}
else
{
if (line1 != null)
{
line1.StrokeDashArray.Clear();
line2.StrokeDashArray.Clear();
}
}
this.HandleLength = wr;
placement = new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Bottom);
placement.YOffset = HandleLengthOffset;
break;
}
}
AdornerPanel.SetPlacement(this, placement);
this.Visibility = Visibility.Visible;
}
}
}

82
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ClearableTextBox.cs

@ -0,0 +1,82 @@ @@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Data;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
public class ClearableTextBox : EnterTextBox
{
private Button textRemoverButton;
static ClearableTextBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof (ClearableTextBox),
new FrameworkPropertyMetadata(typeof (ClearableTextBox)));
}
public ClearableTextBox()
{
this.GotFocus += this.TextBoxGotFocus;
this.LostFocus += this.TextBoxLostFocus;
this.TextChanged += this.TextBoxTextChanged;
this.KeyUp += this.ClearableTextBox_KeyUp;
}
void ClearableTextBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
this.TextRemoverClick(sender, null);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.textRemoverButton = this.GetTemplateChild("TextRemover") as Button;
if (null != this.textRemoverButton)
{
this.textRemoverButton.Click += this.TextRemoverClick;
}
this.UpdateState();
}
protected void UpdateState()
{
if (string.IsNullOrEmpty(this.Text))
{
VisualStateManager.GoToState(this, "TextRemoverHidden", true);
}
else
{
VisualStateManager.GoToState(this, "TextRemoverVisible", true);
}
}
private void TextBoxTextChanged(object sender, TextChangedEventArgs e)
{
this.UpdateState();
}
private void TextRemoverClick(object sender, RoutedEventArgs e)
{
this.Text = string.Empty;
this.Focus();
}
private void TextBoxGotFocus(object sender, RoutedEventArgs e)
{
this.UpdateState();
}
private void TextBoxLostFocus(object sender, RoutedEventArgs e)
{
this.UpdateState();
}
}
}

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);
}
}
}
}

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

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls" xmlns:ControlConvertors="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls.Converters" xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters">
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls" xmlns:ControlConvertors="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls.Converters" xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters" xmlns:Widgets="http://icsharpcode.net/sharpdevelop/widgets">
<!--
This file contains the default styles used by the Controls in ICSharpCode.WpfDesign.Designer.Controls
-->
@ -17,6 +17,11 @@ @@ -17,6 +17,11 @@
<Style TargetType="{x:Type Controls:EnumButton}" BasedOn="{StaticResource {x:Type ToggleButton}}">
<Setter Property="Margin" Value="3 3 0 3" />
<Setter Property="MinWidth" Value="50" />
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="SkyBlue" />
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type Controls:ResizeThumb}">
<Setter Property="Template">
@ -39,6 +44,20 @@ @@ -39,6 +44,20 @@
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:RotateThumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:RotateThumb}">
<Grid>
<Rectangle VerticalAlignment="Top" Width="2" Height="30" Fill="Black" Margin="0,0,0,0" />
<Ellipse VerticalAlignment="Top" StrokeThickness="1" Name="thumbRectangle" SnapsToDevicePixels="True" Stroke="Black"
Width="7" Height="7" Fill="Black">
</Ellipse>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:SelectionFrame}">
<Setter Property="Template">
<Setter.Value>
@ -89,7 +108,7 @@ @@ -89,7 +108,7 @@
<Label Margin="4,0,0,0" Content="{TemplateBinding Window.Title}" />
</DockPanel>
<Border Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<Border BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Background="{TemplateBinding Panel.Background}">
<Border ClipToBounds="True" BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Background="{TemplateBinding Panel.Background}">
<AdornerDecorator>
<ContentPresenter ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" Content="{TemplateBinding ContentControl.Content}" />
</AdornerDecorator>
@ -188,6 +207,45 @@ @@ -188,6 +207,45 @@
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:CanvasPositionHandle}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:MarginHandle}">
<Grid Height="10" Width="{Binding Path=HandleLength, Converter={x:Static ControlConvertors:HandleLengthWithOffset.Instance}, RelativeSource={RelativeSource Mode=TemplatedParent}}" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="8" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Path Name="startArrow" Fill="{StaticResource HandleBrush}" Stretch="Fill" Stroke="{TemplateBinding Panel.Background}" StrokeThickness="0.5" Margin="0,1,0,1" Data="M0,0 L0,1 1,0.5 z" Grid.Column="0" />
<!-- Wrap the handle-line and endArrow in this grid. It's visiblity is subjected to HandleLength -->
<Grid Height="10" Grid.Column="1" Name="lineArrow">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition MaxWidth="20" MinWidth="10" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Fill="Transparent" Height="10" Grid.Column="0" Grid.ColumnSpan="4" />
<Path Name="line1" StrokeDashArray="2,2" Stretch="Fill" Stroke="{StaticResource HandleBrush}" StrokeThickness="1.5" Margin="0 0 0 0" Data="M0,-0.75 L1,-0.75" Grid.Column="0" />
<TextBlock Grid.Column="1" Text="{Binding Path=HandleLength, Mode=OneWay, Converter={x:Static Converters:FormatDoubleConverter.Instance }, RelativeSource={RelativeSource Mode=TemplatedParent}}" FontSize="9" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="1,1,1,1">
<TextBlock.LayoutTransform>
<RotateTransform Angle="{Binding Path=TextTransform, RelativeSource={RelativeSource Mode=TemplatedParent}}" CenterX="0.5" CenterY="0.5">
</RotateTransform>
</TextBlock.LayoutTransform>
</TextBlock>
<Path Name="line2" StrokeDashArray="2,2" Stretch="Fill" Stroke="{StaticResource HandleBrush}" StrokeThickness="1.5" Margin="0 0 0 0" Data="M0,-0.75 L1,-0.75" Grid.Column="2" />
<!--<Path Name="arrow2" Margin="0,1,0,1" Fill="{StaticResource HandleBrush}" Stretch="Fill" Stroke="{TemplateBinding Panel.Background}" StrokeThickness="0.5" Data="M0,0 L0,1 1,0.5 z" Grid.Column="3" />-->
<!--<Rectangle Width="1.5" Fill="{StaticResource HandleBrush}" Grid.Column="4"/>-->
</Grid>
<!-- Rotate the handle and angle of rotation being set by the Margin type. See enum HandleOrientation -->
<Grid.LayoutTransform>
<RotateTransform Angle="{Binding Path=Angle, RelativeSource={RelativeSource Mode=TemplatedParent}}">
</RotateTransform>
</Grid.LayoutTransform>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:MarginHandle}">
<Setter Property="Template">
<Setter.Value>
@ -285,7 +343,7 @@ @@ -285,7 +343,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:InPlaceEditor}">
<TextBox Name="editor" SnapsToDevicePixels="True" Padding="{Binding Path=Padding}" FontSize="{Binding Path=FontSize}" FontFamily="{Binding Path=FontFamily}" FontStyle="{Binding Path=FontStyle}" FontStretch="{Binding Path=FontStretch}" FontWeight="{Binding Path=FontWight}" Text="{Binding Path=Bind, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" />
<TextBox Name="editor" SnapsToDevicePixels="True" Padding="{Binding Path=Padding}" FontSize="{Binding Path=FontSize}" FontFamily="{Binding Path=FontFamily}" FontStyle="{Binding Path=FontStyle}" FontStretch="{Binding Path=FontStretch}" FontWeight="{Binding Path=FontWeight}" Text="{Binding Path=Bind, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" AcceptsReturn="True" />
</ControlTemplate>
</Setter.Value>
</Setter>
@ -305,4 +363,234 @@ @@ -305,4 +363,234 @@
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
<Style TargetType="{x:Type Controls:ZoomControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:ZoomControl}">
<Grid Background="{TemplateBinding Panel.Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Widgets:SelfCollapsingPanel Grid.Column="0" Grid.Row="1" CollapseOrientation="Horizontal" CanCollapse="{Binding Path=ComputedZoomButtonCollapsed, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}">
<Widgets:ZoomButtons x:Name="zoomButtons" Value="{Binding Path=CurrentZoom, RelativeSource={RelativeSource Mode=TemplatedParent}}" Minimum="{TemplateBinding MinimumZoom}" Maximum="{TemplateBinding MaximumZoom}" />
</Widgets:SelfCollapsingPanel>
<Rectangle Grid.Column="2" Grid.Row="1" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<ScrollContentPresenter Name="PART_Presenter" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" Margin="{TemplateBinding Control.Padding}" Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" CanContentScroll="{TemplateBinding ScrollViewer.CanContentScroll}">
<ScrollContentPresenter.LayoutTransform>
<ScaleTransform ScaleX="{Binding Path=CurrentZoom, RelativeSource={RelativeSource Mode=TemplatedParent}}" ScaleY="{Binding Path=CurrentZoom, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
</ScrollContentPresenter.LayoutTransform>
</ScrollContentPresenter>
<ContentControl Grid.Column="1" Grid.Row="1" Content="{TemplateBinding AdditionalControls}" />
<ScrollBar Name="PART_VerticalScrollBar" Grid.Column="3" Grid.Row="0" Minimum="0" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Value="{TemplateBinding VerticalOffset}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" />
<ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Column="2" Grid.Row="1" Minimum="0" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Value="{TemplateBinding HorizontalOffset}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Button}" x:Key="ClearButtonStyle">
<Setter Property="Background" Value="#FFaaaaaa" />
<Setter Property="BorderBrush" Value="#FFaaaaaa" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Width="14" Height="14">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="FocusStates">
<VisualState x:Name="Focused" />
<VisualState x:Name="Unfocused" />
</VisualStateGroup>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="00:00:00.2000000" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Duration="0"
Storyboard.TargetName="ellipseHighlight"
Storyboard.TargetProperty="(UIElement.Opacity)"
To="1" />
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<DoubleAnimation Duration="0"
Storyboard.TargetName="ellipseHighlight"
Storyboard.TargetProperty="(UIElement.Opacity)"
To="1" />
<DoubleAnimation Duration="0"
Storyboard.TargetName="pathHighlight"
Storyboard.TargetProperty="(UIElement.Opacity)"
To="1" />
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Ellipse x:Name="ellipse"
Fill="{TemplateBinding Background}"
Stroke="{TemplateBinding BorderBrush}" />
<Ellipse x:Name="ellipseHighlight"
Fill="#FFBD7777"
Opacity="0"
Stroke="Red" />
<Path x:Name="path"
Margin="4.5"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M0.5,0.5 L8.5,8.5 M8.5000095,0.50000072 L0.50000954,8.500001"
Stretch="Fill"
Stroke="{TemplateBinding Foreground}"
UseLayoutRounding="False" />
<Path x:Name="pathHighlight"
Margin="4.5"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M0.5,0.5 L8.5,8.5 M8.5000095,0.50000072 L0.50000954,8.500001"
Opacity="0"
Stretch="Fill"
Stroke="Red"
UseLayoutRounding="False" />
<ContentPresenter x:Name="contentPresenter"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Visibility="Collapsed" />
<Rectangle x:Name="DisabledVisualElement"
Fill="#FFFFFFFF"
IsHitTestVisible="false"
Opacity="0"
RadiusX="3"
RadiusY="3" />
<Rectangle x:Name="FocusVisualElement"
Margin="1"
IsHitTestVisible="false"
Opacity="0"
RadiusX="2"
RadiusY="2"
Stroke="#FF6DBDD1"
StrokeThickness="1" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:ClearableTextBox}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="BorderBrush" Value="#888" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="1,0,0,0" />
<Setter Property="AllowDrop" Value="true" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:ClearableTextBox}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="TextRemoverStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="00:00:00.3000000" />
</VisualStateGroup.Transitions>
<VisualState x:Name="TextRemoverVisible">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TextRemover"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TextRemover"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TextRemover"
Storyboard.TargetProperty="(UIElement.Opacity)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="TextRemoverHidden">
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TextRemover"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TextRemover"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Duration="00:00:00.0010000"
Storyboard.TargetName="TextRemover"
Storyboard.TargetProperty="(UIElement.Opacity)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="Border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="1" />
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center"
Margin="0,0,18,0"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<Viewbox Stretch="Uniform" HorizontalAlignment="Right" VerticalAlignment="Stretch" Margin="0,3,3,3">
<Button x:Name="TextRemover"
Width="14"
Height="14"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
IsTabStop="False"
RenderTransformOrigin="0.5,0.5"
Style="{StaticResource ClearButtonStyle}">
<Button.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1" />
<SkewTransform />
<RotateTransform />
<TranslateTransform />
</TransformGroup>
</Button.RenderTransform>
</Button>
</Viewbox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:RenderTransformOriginThumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:RenderTransformOriginThumb}">
<Grid>
<Ellipse Width="2" Height="2" Fill="Black"/>
<Ellipse Width="10" Height="10" Fill="Transparent" Stroke="Black" StrokeThickness="2" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GrayOutDesignerExceptActiveArea.cs

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using System.Windows.Media.Animation;
@ -78,7 +79,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -78,7 +79,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
if (designPanel != null && grayOut == null && optionService != null && optionService.GrayOutDesignSurfaceExceptParentContainerWhenDragging) {
grayOut = new GrayOutDesignerExceptActiveArea();
grayOut.designSurfaceRectangle = new RectangleGeometry(
new Rect(new Point(0, 0), designPanel.RenderSize));
new Rect(0, 0, ((Border)designPanel.Child).Child.RenderSize.Width, ((Border)designPanel.Child).Child.RenderSize.Height));
grayOut.designPanel = designPanel;
grayOut.adornerPanel = new AdornerPanel();
grayOut.adornerPanel.Order = AdornerOrder.BehindForeground;

101
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/InfoTextEnterArea.cs

@ -0,0 +1,101 @@ @@ -0,0 +1,101 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using System.Windows.Media.Animation;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Gray out everything except a specific area.
/// </summary>
sealed class InfoTextEnterArea : FrameworkElement
{
Geometry designSurfaceRectangle;
Geometry activeAreaGeometry;
Geometry combinedGeometry;
AdornerPanel adornerPanel;
IDesignPanel designPanel;
const double MaxOpacity = 0.3;
public InfoTextEnterArea()
{
this.IsHitTestVisible = false;
}
public Geometry ActiveAreaGeometry {
get { return activeAreaGeometry; }
set {
activeAreaGeometry = value;
combinedGeometry = activeAreaGeometry;
}
}
Rect currentAnimateActiveAreaRectToTarget;
internal void AnimateActiveAreaRectTo(Rect newRect)
{
if (newRect.Equals(currentAnimateActiveAreaRectToTarget))
return;
activeAreaGeometry.BeginAnimation(
RectangleGeometry.RectProperty,
new RectAnimation(newRect, new Duration(new TimeSpan(0,0,0,0,100))),
HandoffBehavior.SnapshotAndReplace);
currentAnimateActiveAreaRectToTarget = newRect;
}
internal static void Start(ref InfoTextEnterArea grayOut, ServiceContainer services, UIElement activeContainer, string text)
{
Debug.Assert(activeContainer != null);
Start(ref grayOut, services, activeContainer, new Rect(activeContainer.RenderSize), text);
}
internal static void Start(ref InfoTextEnterArea grayOut, ServiceContainer services, UIElement activeContainer, Rect activeRectInActiveContainer, string text)
{
Debug.Assert(services != null);
Debug.Assert(activeContainer != null);
DesignPanel designPanel = services.GetService<IDesignPanel>() as DesignPanel;
OptionService optionService = services.GetService<OptionService>();
if (designPanel != null && grayOut == null && optionService != null && optionService.GrayOutDesignSurfaceExceptParentContainerWhenDragging) {
grayOut = new InfoTextEnterArea();
grayOut.designSurfaceRectangle = new RectangleGeometry(
new Rect(0, 0, ((Border)designPanel.Child).Child.RenderSize.Width, ((Border)designPanel.Child).Child.RenderSize.Height));
grayOut.designPanel = designPanel;
grayOut.adornerPanel = new AdornerPanel();
grayOut.adornerPanel.Order = AdornerOrder.Background;
grayOut.adornerPanel.SetAdornedElement(designPanel.Context.RootItem.View, null);
grayOut.ActiveAreaGeometry = new RectangleGeometry(activeRectInActiveContainer, 0, 0, (Transform)activeContainer.TransformToVisual(grayOut.adornerPanel.AdornedElement));
var tb = new TextBlock(){Text = text};
tb.FontSize = 10;
tb.ClipToBounds = true;
tb.Width = ((FrameworkElement) activeContainer).ActualWidth;
tb.Height = ((FrameworkElement) activeContainer).ActualHeight;
tb.VerticalAlignment = VerticalAlignment.Top;
tb.HorizontalAlignment = HorizontalAlignment.Left;
tb.RenderTransform = (Transform)activeContainer.TransformToVisual(grayOut.adornerPanel.AdornedElement);
grayOut.adornerPanel.Children.Add(tb);
designPanel.Adorners.Add(grayOut.adornerPanel);
}
}
static readonly TimeSpan animationTime = new TimeSpan(2000000);
internal static void Stop(ref InfoTextEnterArea grayOut)
{
if (grayOut != null) {
IDesignPanel designPanel = grayOut.designPanel;
AdornerPanel adornerPanelToRemove = grayOut.adornerPanel;
designPanel.Adorners.Remove(adornerPanelToRemove);
grayOut = null;
}
}
}
}

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/MarginHandle.cs

@ -60,7 +60,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -60,7 +60,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// <summary>
/// Gets the Stub for this handle
/// </summary>
public MarginStub Stub {get; private set;}
public MarginStub Stub {get; protected set;}
/// <summary>
/// Gets/Sets the angle by which handle rotates.
@ -70,7 +70,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -70,7 +70,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// <summary>
/// Gets/Sets the angle by which the Margin display has to be rotated
/// </summary>
public double TextTransform{
public virtual double TextTransform{
get{
if((double)orientation==90 || (double)orientation == 180)
return 180;
@ -109,6 +109,9 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -109,6 +109,9 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
get { return orientation; }
}
protected MarginHandle()
{ }
public MarginHandle(DesignItem adornedControlItem, AdornerPanel adornerPanel, HandleOrientation orientation)
{
Debug.Assert(adornedControlItem!=null);

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);
}
}
}
}

227
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs

@ -6,6 +6,11 @@ using System.Collections.Generic; @@ -6,6 +6,11 @@ using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
@ -13,106 +18,124 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -13,106 +18,124 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// A Small icon which shows up a menu containing common properties
/// </summary>
public class QuickOperationMenu : Control
{
static QuickOperationMenu()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof (QuickOperationMenu), new FrameworkPropertyMetadata(typeof (QuickOperationMenu)));
}
private MenuItem _mainHeader;
/// <summary>
/// Contains Default values in the Sub menu for example "HorizontalAlignment" has "HorizontalAlignment.Stretch" as it's value.
/// </summary>
private readonly Dictionary<MenuItem, MenuItem> _defaults = new Dictionary<MenuItem, MenuItem>();
/// <summary>
/// Is the main header menu which brings up all the menus.
/// </summary>
public MenuItem MainHeader {
get { return _mainHeader; }
}
/// <summary>
/// Add a submenu with checkable values.
/// </summary>
/// <param name="parent">The parent menu under which to add.</param>
/// <param name="enumValues">All the values of an enum to be showed in the menu</param>
/// <param name="defaultValue">The default value out of all the enums.</param>
/// <param name="setValue">The presently set value out of the enums</param>
public void AddSubMenuCheckable(MenuItem parent, Array enumValues, string defaultValue, string setValue)
{
foreach (var enumValue in enumValues) {
var menuItem = new MenuItem {Header = enumValue.ToString(), IsCheckable = true};
parent.Items.Add(menuItem);
if (enumValue.ToString() == defaultValue)
_defaults.Add(parent, menuItem);
if (enumValue.ToString() == setValue)
menuItem.IsChecked = true;
}
}
/// <summary>
/// Add a menu in the main header.
/// </summary>
/// <param name="menuItem">The menu to add.</param>
public void AddSubMenuInTheHeader(MenuItem menuItem)
{
if (_mainHeader != null)
_mainHeader.Items.Add(menuItem);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var mainHeader = Template.FindName("MainHeader", this) as MenuItem;
if (mainHeader != null) {
_mainHeader = mainHeader;
}
}
/// <summary>
/// Checks a menu item and making it exclusive. If the check was toggled then the default menu item is selected.
/// </summary>
/// <param name="parent">The parent item of the sub menu</param>
/// <param name="clickedOn">The Item clicked on</param>
/// <returns>Returns the Default value if the checkable menu item is toggled or otherwise the new checked menu item.</returns>
public string UncheckChildrenAndSelectClicked(MenuItem parent, MenuItem clickedOn)
{
MenuItem defaultMenuItem;
_defaults.TryGetValue(parent, out defaultMenuItem);
if (IsAnyItemChecked(parent)) {
foreach (var item in parent.Items) {
var menuItem = item as MenuItem;
if (menuItem != null) menuItem.IsChecked = false;
}
clickedOn.IsChecked = true;
return (string) clickedOn.Header;
} else {
if (defaultMenuItem != null) {
defaultMenuItem.IsChecked = true;
return (string) defaultMenuItem.Header;
}
}
return null;
}
/// <summary>
/// Checks in the sub-menu whether aby items has been checked or not
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
private bool IsAnyItemChecked(MenuItem parent)
{
bool check = false;
if (parent.HasItems) {
foreach (var item in parent.Items) {
var menuItem = item as MenuItem;
if (menuItem != null && menuItem.IsChecked)
check = true;
}
}
return check;
}
}
{
static QuickOperationMenu()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof (QuickOperationMenu), new FrameworkPropertyMetadata(typeof (QuickOperationMenu)));
}
public QuickOperationMenu()
{
scaleTransform = new ScaleTransform(1.0, 1.0);
this.LayoutTransform = scaleTransform;
}
private ScaleTransform scaleTransform;
private MenuItem _mainHeader;
/// <summary>
/// Contains Default values in the Sub menu for example "HorizontalAlignment" has "HorizontalAlignment.Stretch" as it's value.
/// </summary>
private readonly Dictionary<MenuItem, MenuItem> _defaults = new Dictionary<MenuItem, MenuItem>();
/// <summary>
/// Is the main header menu which brings up all the menus.
/// </summary>
public MenuItem MainHeader {
get { return _mainHeader; }
}
/// <summary>
/// Add a submenu with checkable values.
/// </summary>
/// <param name="parent">The parent menu under which to add.</param>
/// <param name="enumValues">All the values of an enum to be showed in the menu</param>
/// <param name="defaultValue">The default value out of all the enums.</param>
/// <param name="setValue">The presently set value out of the enums</param>
public void AddSubMenuCheckable(MenuItem parent, Array enumValues, string defaultValue, string setValue)
{
foreach (var enumValue in enumValues) {
var menuItem = new MenuItem {Header = enumValue.ToString(), IsCheckable = true};
parent.Items.Add(menuItem);
if (enumValue.ToString() == defaultValue)
_defaults.Add(parent, menuItem);
if (enumValue.ToString() == setValue)
menuItem.IsChecked = true;
}
}
/// <summary>
/// Add a menu in the main header.
/// </summary>
/// <param name="menuItem">The menu to add.</param>
public void AddSubMenuInTheHeader(MenuItem menuItem)
{
if (_mainHeader != null)
_mainHeader.Items.Add(menuItem);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var mainHeader = Template.FindName("MainHeader", this) as MenuItem;
if (mainHeader != null) {
_mainHeader = mainHeader;
}
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);
}
}
/// <summary>
/// Checks a menu item and making it exclusive. If the check was toggled then the default menu item is selected.
/// </summary>
/// <param name="parent">The parent item of the sub menu</param>
/// <param name="clickedOn">The Item clicked on</param>
/// <returns>Returns the Default value if the checkable menu item is toggled or otherwise the new checked menu item.</returns>
public string UncheckChildrenAndSelectClicked(MenuItem parent, MenuItem clickedOn)
{
MenuItem defaultMenuItem;
_defaults.TryGetValue(parent, out defaultMenuItem);
if (IsAnyItemChecked(parent)) {
foreach (var item in parent.Items) {
var menuItem = item as MenuItem;
if (menuItem != null) menuItem.IsChecked = false;
}
clickedOn.IsChecked = true;
return (string) clickedOn.Header;
} else {
if (defaultMenuItem != null) {
defaultMenuItem.IsChecked = true;
return (string) defaultMenuItem.Header;
}
}
return null;
}
/// <summary>
/// Checks in the sub-menu whether aby items has been checked or not
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
private bool IsAnyItemChecked(MenuItem parent)
{
bool check = false;
if (parent.HasItems) {
foreach (var item in parent.Items) {
var menuItem = item as MenuItem;
if (menuItem != null && menuItem.IsChecked)
check = true;
}
}
return check;
}
}
}

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

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Description of RenderTransformThumb.
/// </summary>
public class RenderTransformOriginThumb : Thumb
{
static RenderTransformOriginThumb()
{
//This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
//This style is defined in themes\generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(typeof(RenderTransformOriginThumb), new FrameworkPropertyMetadata(typeof(RenderTransformOriginThumb)));
}
}
}

35
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/RotateThumb.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
public class RotateThumb : ResizeThumb
{
private double initialAngle;
private RotateTransform rotateTransform;
private Vector startVector;
private Point centerPoint;
private Control designerItem;
private Panel canvas;
private AdornerPanel parent;
static RotateThumb()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(RotateThumb), new FrameworkPropertyMetadata(typeof(RotateThumb)));
}
public RotateThumb()
{
this.ResizeThumbVisible = true;
}
}
}

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ZoomControl.cs

@ -18,9 +18,19 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -18,9 +18,19 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
{
PanToolCursor = GetCursor("Images/PanToolCursor.cur");
PanToolCursorMouseDown = GetCursor("Images/PanToolCursorMouseDown.cur");
DefaultStyleKeyProperty.OverrideMetadata(typeof(ZoomControl), new FrameworkPropertyMetadata(typeof(ZoomControl)));
}
public object AdditionalControls
{
get { return (object)GetValue(AdditionalControlsProperty); }
set { SetValue(AdditionalControlsProperty, value); }
}
static Cursor GetCursor(string path)
public static readonly DependencyProperty AdditionalControlsProperty =
DependencyProperty.Register("AdditionalControls", typeof(object), typeof(ZoomControl), new PropertyMetadata(null));
internal static Cursor GetCursor(string path)
{
var a = Assembly.GetExecutingAssembly();
var m = new ResourceManager(a.GetName().Name + ".g", a);

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

@ -9,6 +9,7 @@ using System.Windows.Data; @@ -9,6 +9,7 @@ using System.Windows.Data;
using System.Globalization;
using System.Windows;
using System.Collections;
using System.Windows.Media;
namespace ICSharpCode.WpfDesign.Designer.Converters
{
@ -85,7 +86,7 @@ namespace ICSharpCode.WpfDesign.Designer.Converters @@ -85,7 +86,7 @@ namespace ICSharpCode.WpfDesign.Designer.Converters
{
if (value == null || (int)value == 0) {
return Visibility.Collapsed;
}
}
return Visibility.Visible;
}
@ -145,17 +146,109 @@ namespace ICSharpCode.WpfDesign.Designer.Converters @@ -145,17 +146,109 @@ namespace ICSharpCode.WpfDesign.Designer.Converters
}
public class FormatDoubleConverter : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly FormatDoubleConverter Instance=new FormatDoubleConverter();
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly FormatDoubleConverter Instance=new FormatDoubleConverter();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Math.Round((double)value);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class BlackWhenTrue : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly BlackWhenTrue Instance = new BlackWhenTrue();
private Brush black = new SolidColorBrush(Colors.Black);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? black : null;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Math.Round((double)value);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
public class EnumBoolean : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly EnumBoolean Instance = new EnumBoolean();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;
if (Enum.IsDefined(value.GetType(), value) == false)
return DependencyProperty.UnsetValue;
object parameterValue = Enum.Parse(value.GetType(), parameterString);
return parameterValue.Equals(value);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;
return Enum.Parse(targetType, parameterString);
}
}
public class EnumVisibility : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly EnumVisibility Instance = new EnumVisibility();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;
if (Enum.IsDefined(value.GetType(), value) == false)
return DependencyProperty.UnsetValue;
object parameterValue = Enum.Parse(value.GetType(), parameterString);
return parameterValue.Equals(value) ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string parameterString = parameter as string;
if (parameterString == null)
return DependencyProperty.UnsetValue;
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);
}
}
}

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

@ -16,7 +16,7 @@ using ICSharpCode.WpfDesign.Designer.Controls; @@ -16,7 +16,7 @@ using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer
{
sealed class DesignPanel : Decorator, IDesignPanel
public sealed class DesignPanel : Decorator, IDesignPanel, INotifyPropertyChanged
{
#region Hit Testing
/// <summary>
@ -147,6 +147,9 @@ namespace ICSharpCode.WpfDesign.Designer @@ -147,6 +147,9 @@ namespace ICSharpCode.WpfDesign.Designer
};
_eatAllHitTestRequests.AllowDrop = true;
_adornerLayer = new AdornerLayer(this);
this.PreviewKeyUp += DesignPanel_KeyUp;
this.PreviewKeyDown += DesignPanel_KeyDown;
}
#endregion
@ -182,6 +185,36 @@ namespace ICSharpCode.WpfDesign.Designer @@ -182,6 +185,36 @@ namespace ICSharpCode.WpfDesign.Designer
set { _adornerLayer.IsHitTestVisible = value; }
}
/// <summary>
/// Enables / Disables the Snapline Placement
/// </summary>
private bool _useSnaplinePlacement = true;
public bool UseSnaplinePlacement
{
get { return _useSnaplinePlacement; }
set { _useSnaplinePlacement = value; OnPropertyChanged("UseSnaplinePlacement"); }
}
/// <summary>
/// Enables / Disables the Raster Placement
/// </summary>
private bool _useRasterPlacement = false;
public bool UseRasterPlacement
{
get { return _useRasterPlacement; }
set { _useRasterPlacement = value; OnPropertyChanged("UseRasterPlacement"); }
}
/// <summary>
/// Sets the with of the Raster when using Raster Placement
/// </summary>
private int _rasterWidth = 5;
public int RasterWidth
{
get { return _rasterWidth; }
set { _rasterWidth = value; OnPropertyChanged("RasterWidth"); }
}
#endregion
#region Visual Child Management
@ -249,6 +282,49 @@ namespace ICSharpCode.WpfDesign.Designer @@ -249,6 +282,49 @@ namespace ICSharpCode.WpfDesign.Designer
}
#endregion
private void DesignPanel_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
{
e.Handled = true;
}
}
void DesignPanel_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
{
e.Handled = true;
var placementOp = PlacementOperation.Start(Context.Services.Selection.SelectedItems, PlacementType.Move);
var dx1 = (e.Key == Key.Left) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0;
var dy1 = (e.Key == Key.Up) ? Keyboard.IsKeyDown(Key.LeftShift) ? -10 : -1 : 0;
var dx2 = (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : 0;
var dy2 = (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? 10 : 1 : 0;
foreach (PlacementInformation info in placementOp.PlacedItems)
{
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
{
info.Bounds = new Rect(info.OriginalBounds.Left + dx1 + dx2,
info.OriginalBounds.Top + dy1 + dy2,
info.OriginalBounds.Width,
info.OriginalBounds.Height);
}
else
{
info.Bounds = new Rect(info.OriginalBounds.Left,
info.OriginalBounds.Top,
info.OriginalBounds.Width + dx1 + dx2,
info.OriginalBounds.Height + dy1 + dy2);
}
placementOp.CurrentContainerBehavior.SetPosition(info);
}
}
}
protected override void OnQueryCursor(QueryCursorEventArgs e)
{
base.OnQueryCursor(e);
@ -260,5 +336,12 @@ namespace ICSharpCode.WpfDesign.Designer @@ -260,5 +336,12 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

75
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs

@ -17,6 +17,8 @@ using System.Windows.Shapes; @@ -17,6 +17,8 @@ using System.Windows.Shapes;
using System.Xml;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Designer.Services;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using System.Diagnostics;
using ICSharpCode.WpfDesign.XamlDom;
using System.Threading;
@ -27,18 +29,21 @@ namespace ICSharpCode.WpfDesign.Designer @@ -27,18 +29,21 @@ namespace ICSharpCode.WpfDesign.Designer
/// <summary>
/// Surface hosting the WPF designer.
/// </summary>
public partial class DesignSurface
[TemplatePart(Name = "PART_DesignContent", Type = typeof(ContentControl))]
[TemplatePart(Name = "PART_Zoom", Type = typeof(ZoomControl))]
public class DesignSurface : ContentControl
{
private FocusNavigator _focusNav;
static DesignSurface()
{
//TODO: this is for converters (see PropertyGrid)
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
DefaultStyleKeyProperty.OverrideMetadata(typeof(DesignSurface), new FrameworkPropertyMetadata(typeof(DesignSurface)));
}
public DesignSurface()
{
InitializeComponent();
//TODO: this is for converters (see PropertyGrid)
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
this.AddCommandHandler(ApplicationCommands.Undo, Undo, CanUndo);
this.AddCommandHandler(ApplicationCommands.Redo, Redo, CanRedo);
@ -48,23 +53,42 @@ namespace ICSharpCode.WpfDesign.Designer @@ -48,23 +53,42 @@ namespace ICSharpCode.WpfDesign.Designer
this.AddCommandHandler(ApplicationCommands.Paste, Paste, CanPaste);
this.AddCommandHandler(ApplicationCommands.SelectAll, SelectAll, CanSelectAll);
#if DEBUG || CODE_ANALYSIS
if (_designPanel == null) {
Environment.FailFast("designpanel should be initialized earlier");
// Fake call to DesignPanel constructor because FxCop doesn't look inside XAML files
// and we'd get tons of warnings about uncalled private code.
_designPanel = new DesignPanel();
}
#endif
_sceneContainer = new Border() { AllowDrop = false, UseLayoutRounding = true };
_sceneContainer.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal);
_designPanel = new DesignPanel() {Child = _sceneContainer};
}
internal DesignPanel _designPanel;
private ContentControl _partDesignContent;
private Border _sceneContainer;
public override void OnApplyTemplate()
{
_partDesignContent = this.Template.FindName("PART_DesignContent", this) as ContentControl;
_partDesignContent.Content = _designPanel;
_partDesignContent.RequestBringIntoView += _partDesignContent_RequestBringIntoView;
this.ZoomControl = this.Template.FindName("PART_Zoom", this) as ZoomControl;
base.OnApplyTemplate();
}
void _partDesignContent_RequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
e.Handled = true;
}
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
{
if (e.OriginalSource == uxZoom) {
if (ZoomControl != null && e.OriginalSource == ZoomControl)
{
UnselectAll();
}
}
public ZoomControl ZoomControl { get; private set; }
DesignContext _designContext;
/// <summary>
@ -74,6 +98,13 @@ namespace ICSharpCode.WpfDesign.Designer @@ -74,6 +98,13 @@ namespace ICSharpCode.WpfDesign.Designer
get { return _designContext; }
}
/// <summary>
/// Gets the DesignPanel
/// </summary>
public DesignPanel DesignPanel {
get { return _designPanel; }
}
/// <summary>
/// Initializes the designer content from the specified XmlReader.
/// </summary>
@ -127,7 +158,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -127,7 +158,7 @@ namespace ICSharpCode.WpfDesign.Designer
IDisposable d = o as IDisposable;
if (d != null) d.Dispose();
}
}
}
_designContext = null;
_designPanel.Context = null;
_sceneContainer.Child = null;
@ -170,18 +201,18 @@ namespace ICSharpCode.WpfDesign.Designer @@ -170,18 +201,18 @@ namespace ICSharpCode.WpfDesign.Designer
{
ISelectionService selectionService = GetService<ISelectionService>();
if(selectionService!=null){
if (selectionService.SelectedItems.Count == 0)
return false;
if (selectionService.SelectedItems.Count == 1 && selectionService.PrimarySelection == DesignContext.RootItem)
return false;
if (selectionService.SelectedItems.Count == 0)
return false;
if (selectionService.SelectedItems.Count == 1 && selectionService.PrimarySelection == DesignContext.RootItem)
return false;
}
return true;
return true;
}
public void Copy()
{
XamlDesignContext xamlContext = _designContext as XamlDesignContext;
ISelectionService selectionService = GetService<ISelectionService>();
ISelectionService selectionService = GetService<ISelectionService>();
if(xamlContext != null && selectionService != null){
xamlContext.XamlEditAction.Copy(selectionService.SelectedItems);
}
@ -190,7 +221,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -190,7 +221,7 @@ namespace ICSharpCode.WpfDesign.Designer
public void Cut()
{
XamlDesignContext xamlContext = _designContext as XamlDesignContext;
ISelectionService selectionService = GetService<ISelectionService>();
ISelectionService selectionService = GetService<ISelectionService>();
if(xamlContext != null && selectionService != null){
xamlContext.XamlEditAction.Cut(selectionService.SelectedItems);
}

52
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.xaml

@ -1,14 +1,38 @@ @@ -1,14 +1,38 @@
<UserControl x:Class="ICSharpCode.WpfDesign.Designer.DesignSurface"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Default="clr-namespace:ICSharpCode.WpfDesign.Designer"
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls"
DataContext="{x:Null}"
Background="#888">
<Controls:ZoomControl x:Name="uxZoom" AlwaysShowZoomButtons="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<Default:DesignPanel x:Name="_designPanel">
<!-- Reset some inherited properties to the WPF defaults to avoid values from SharpDevelop applying to designed forms. -->
<Border x:Name="_sceneContainer" AllowDrop="False" UseLayoutRounding="False" TextOptions.TextFormattingMode="Ideal" />
</Default:DesignPanel>
</Controls:ZoomControl>
</UserControl>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Default="clr-namespace:ICSharpCode.WpfDesign.Designer"
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls"
xmlns:Designer="clr-namespace:ICSharpCode.WpfDesign.Designer"
xmlns:Widgets="http://icsharpcode.net/sharpdevelop/widgets">
<Style TargetType="{x:Type Designer:DesignSurface}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Designer:DesignSurface}">
<Controls:ZoomControl Background="#888" x:Name="PART_Zoom" MinimumZoom="0.025" AlwaysShowZoomButtons="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<Controls:ZoomControl.AdditionalControls>
<StackPanel Orientation="Horizontal">
<Controls:EnumButton DataContext="{Binding ElementName=PART_DesignContent}" Margin="0" MinWidth="16" Height="16" Width="16" IsChecked="{Binding ElementName=PART_DesignContent, Path=Content.UseRasterPlacement, Mode=TwoWay}" ToolTip="Use Raster Placement">
<Controls:EnumButton.ContextMenu>
<ContextMenu DataContext="{Binding PlacementTarget.DataContext,RelativeSource={RelativeSource Self}}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="RasterWidth:" />
<Widgets:NumericUpDown Width="40" Margin="5,0,0,0" Value="{Binding Path=Content.RasterWidth, Mode=TwoWay}"/>
</StackPanel>
</ContextMenu>
</Controls:EnumButton.ContextMenu>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/Raster.png" Stretch="Uniform" />
</Controls:EnumButton>
<Controls:EnumButton Margin="0" MinWidth="16" Height="16" Width="16" IsChecked="{Binding ElementName=PART_DesignContent, Path=Content.UseSnaplinePlacement, Mode=TwoWay}" ToolTip="Use Snapline Placement">
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/Snapline.png" Stretch="Uniform" />
</Controls:EnumButton>
</StackPanel>
</Controls:ZoomControl.AdditionalControls>
<ContentControl x:Name="PART_DesignContent" />
</Controls:ZoomControl>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

64
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/BorderForInvisibleControl.cs

@ -15,20 +15,68 @@ using System.Windows.Media; @@ -15,20 +15,68 @@ using System.Windows.Media;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionFor(typeof(Panel))]
[ExtensionFor(typeof(Border))]
[ExtensionFor(typeof(ContentControl))]
[ExtensionFor(typeof(Viewbox))]
public class BorderForInvisibleControl : PermanentAdornerProvider
{
AdornerPanel adornerPanel;
protected override void OnInitialized()
{
base.OnInitialized();
var adornerPanel = new AdornerPanel();
var border = new Border();
border.BorderThickness = new Thickness(1);
border.BorderBrush = new SolidColorBrush(Color.FromRgb(0xCC, 0xCC, 0xCC));
border.IsHitTestVisible = false;
AdornerPanel.SetPlacement(border, AdornerPlacement.FillContent);
adornerPanel.Children.Add(border);
Adorners.Add(adornerPanel);
if (ExtendedItem.Component is Border)
{
ExtendedItem.PropertyChanged+= (s, e) => ExtendedItem_PropertyChanged();
ExtendedItem_PropertyChanged();
}
else if (ExtendedItem.Component is Panel || ExtendedItem.Component is Viewbox || ExtendedItem.Component is ContentControl)
{
CreateAdorner();
}
}
void ExtendedItem_PropertyChanged()
{
if (ExtendedItem.Component is Border)
{
var border = ExtendedItem.Component as Border;
if (border.ReadLocalValue(Border.BorderBrushProperty) == DependencyProperty.UnsetValue || border.ReadLocalValue(Border.BorderThicknessProperty) == DependencyProperty.UnsetValue)
{
CreateAdorner();
}
else
{
RemoveAdorner();
}
}
}
private void CreateAdorner()
{
if (adornerPanel == null)
{
adornerPanel = new AdornerPanel();
adornerPanel.Order = AdornerOrder.Background;
var border = new Border();
border.BorderThickness = new Thickness(1);
border.BorderBrush = new SolidColorBrush(Color.FromRgb(0xCC, 0xCC, 0xCC));
border.IsHitTestVisible = false;
AdornerPanel.SetPlacement(border, AdornerPlacement.FillContent);
adornerPanel.Children.Add(border);
Adorners.Add(adornerPanel);
}
}
private void RemoveAdorner()
{
if (adornerPanel != null)
{
Adorners.Remove(adornerPanel);
adornerPanel = null;
}
}
}
}

56
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

@ -17,22 +17,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -17,22 +17,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
[ExtensionFor(typeof(Canvas), OverrideExtension=typeof(DefaultPlacementBehavior))]
public sealed class CanvasPlacementSupport : SnaplinePlacementBehavior
{
static double GetLeft(UIElement element)
GrayOutDesignerExceptActiveArea grayOut;
static double GetCanvasProperty(UIElement element, DependencyProperty d)
{
double v = (double)element.GetValue(Canvas.LeftProperty);
double v = (double)element.GetValue(d);
if (double.IsNaN(v))
return 0;
else
return v;
}
static double GetTop(UIElement element)
static bool IsPropertySet(UIElement element, DependencyProperty d)
{
double v = (double)element.GetValue(Canvas.TopProperty);
if (double.IsNaN(v))
return 0;
else
return v;
return element.ReadLocalValue(d) != DependencyProperty.UnsetValue;
}
public override void SetPosition(PlacementInformation info)
@ -43,16 +41,48 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -43,16 +41,48 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
UIElement child = info.Item.View;
Rect newPosition = info.Bounds;
if (newPosition.Left != GetLeft(child)) {
if (IsPropertySet(child, Canvas.RightProperty))
{
var newR = ((Canvas) ExtendedItem.Component).ActualWidth - newPosition.Right;
if (newR != GetCanvasProperty(child, Canvas.RightProperty))
info.Item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(newR);
}
else if (newPosition.Left != GetCanvasProperty(child, Canvas.LeftProperty))
{
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(newPosition.Left);
}
if (newPosition.Top != GetTop(child)) {
if (IsPropertySet(child, Canvas.BottomProperty))
{
var newB = ((Canvas)ExtendedItem.Component).ActualHeight - newPosition.Bottom;
if (newB != GetCanvasProperty(child, Canvas.BottomProperty))
info.Item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(newB);
}
else if (newPosition.Top != GetCanvasProperty(child, Canvas.TopProperty))
{
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(newPosition.Top);
}
if (info.Item == Services.Selection.PrimarySelection)
{
var cv = this.ExtendedItem.View as Canvas;
var b = new Rect(0, 0, cv.ActualWidth, cv.ActualHeight);
// only for primary selection:
if (grayOut != null)
{
grayOut.AnimateActiveAreaRectTo(b);
}
else
{
GrayOutDesignerExceptActiveArea.Start(ref grayOut, this.Services, this.ExtendedItem.View, b);
}
}
}
public override void LeaveContainer(PlacementOperation operation)
{
GrayOutDesignerExceptActiveArea.Stop(ref grayOut);
base.LeaveContainer(operation);
foreach (PlacementInformation info in operation.PlacedItems) {
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset();
@ -69,5 +99,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -69,5 +99,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
info.Item.Properties[FrameworkElement.MarginProperty].Reset();
}
}
public override void EndPlacement(PlacementOperation operation)
{
GrayOutDesignerExceptActiveArea.Stop(ref grayOut);
base.EndPlacement(operation);
}
}
}

77
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPositionExtension.cs

@ -0,0 +1,77 @@ @@ -0,0 +1,77 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Input;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionFor(typeof(FrameworkElement))]
[ExtensionServer(typeof(PrimarySelectionExtensionServer))]
public class CanvasPositionExtension : AdornerProvider
{
private MarginHandle[] _handles;
private MarginHandle _leftHandle, _topHandle, _rightHandle, _bottomHandle;
private Canvas _canvas;
protected override void OnInitialized()
{
base.OnInitialized();
if (this.ExtendedItem.Parent != null)
{
if (this.ExtendedItem.Parent.ComponentType == typeof(Canvas))
{
FrameworkElement extendedControl = (FrameworkElement)this.ExtendedItem.Component;
AdornerPanel adornerPanel = new AdornerPanel();
// If the Element is rotated/skewed in the grid, then margin handles do not appear
if (extendedControl.LayoutTransform.Value == Matrix.Identity && extendedControl.RenderTransform.Value == Matrix.Identity)
{
_canvas = this.ExtendedItem.Parent.View as Canvas;
_handles = new[]
{
_leftHandle = new CanvasPositionHandle(ExtendedItem, adornerPanel, HandleOrientation.Left),
_topHandle = new CanvasPositionHandle(ExtendedItem, adornerPanel, HandleOrientation.Top),
_rightHandle = new CanvasPositionHandle(ExtendedItem, adornerPanel, HandleOrientation.Right),
_bottomHandle = new CanvasPositionHandle(ExtendedItem, adornerPanel, HandleOrientation.Bottom),
};
}
if (adornerPanel != null)
this.Adorners.Add(adornerPanel);
}
}
}
public void HideHandles()
{
if (_handles != null)
{
foreach (var handle in _handles)
{
handle.ShouldBeVisible = false;
handle.Visibility = Visibility.Hidden;
}
}
}
public void ShowHandles()
{
if (_handles != null)
{
foreach (var handle in _handles)
{
handle.ShouldBeVisible = true;
handle.Visibility = Visibility.Visible;
handle.DecideVisiblity(handle.HandleLength);
}
}
}
}
}

41
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs

@ -5,6 +5,7 @@ using System; @@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using ICSharpCode.WpfDesign.Extensions;
using System.Windows.Controls;
using System.Windows;
@ -18,6 +19,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -18,6 +19,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionFor(typeof(Panel))]
[ExtensionFor(typeof(ContentControl))]
[ExtensionFor(typeof(Border))]
[ExtensionFor(typeof(Viewbox))]
public class DefaultPlacementBehavior : BehaviorExtension, IPlacementBehavior
{
static List<Type> _contentControlsNotAllowedToAdd;
@ -30,7 +33,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -30,7 +33,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
_contentControlsNotAllowedToAdd.Add(typeof (HeaderedContentControl));
_contentControlsNotAllowedToAdd.Add(typeof (Label));
_contentControlsNotAllowedToAdd.Add(typeof (ListBoxItem));
_contentControlsNotAllowedToAdd.Add(typeof (ButtonBase));
//_contentControlsNotAllowedToAdd.Add(typeof (ButtonBase));
_contentControlsNotAllowedToAdd.Add(typeof (StatusBarItem));
_contentControlsNotAllowedToAdd.Add(typeof (ToolTip));
}
@ -61,6 +64,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -61,6 +64,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public virtual void EndPlacement(PlacementOperation operation)
{
InfoTextEnterArea.Stop(ref infoTextEnterArea);
}
public virtual Rect GetPosition(PlacementOperation operation, DesignItem item)
@ -96,8 +100,41 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -96,8 +100,41 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
public virtual bool CanEnterContainer(PlacementOperation operation)
private static InfoTextEnterArea infoTextEnterArea;
public virtual bool CanEnterContainer(PlacementOperation operation, bool shouldAlwaysEnter)
{
var canEnter = internalCanEnterContainer(operation);
if (canEnter && !shouldAlwaysEnter && !Keyboard.IsKeyDown(Key.LeftAlt) && !Keyboard.IsKeyDown(Key.RightAlt))
{
var b = new Rect(0, 0, ((FrameworkElement)this.ExtendedItem.View).ActualWidth, ((FrameworkElement)this.ExtendedItem.View).ActualHeight);
InfoTextEnterArea.Start(ref infoTextEnterArea, this.Services, this.ExtendedItem.View, b, Translations.Instance.PressAltText);
return false;
}
return canEnter;
}
private bool internalCanEnterContainer(PlacementOperation operation)
{
InfoTextEnterArea.Stop(ref infoTextEnterArea);
if (ExtendedItem.Component is Expander)
{
if (!((Expander) ExtendedItem.Component).IsExpanded)
{
((Expander) ExtendedItem.Component).IsExpanded = true;
}
}
if (ExtendedItem.Component is UserControl && ExtendedItem.ComponentType != typeof(UserControl))
return false;
if (ExtendedItem.Component is Decorator)
return ((Decorator)ExtendedItem.Component).Child == null;
if (ExtendedItem.ContentProperty.IsCollection)
return CollectionSupport.CanCollectionAdd(ExtendedItem.ContentProperty.ReturnType,
operation.PlacedItems.Select(p => p.Item.Component));

48
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs

@ -15,13 +15,55 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers @@ -15,13 +15,55 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers
{
public override void InitializeDefaults(DesignItem item)
{
DesignItemProperty contentProperty = item.Properties["Content"];
if (contentProperty.ValueOnInstance == null) {
contentProperty.SetValue(item.ComponentType.Name);
//Not every Content Control can have a text as Content (e.g. ZoomBox of WPF Toolkit)
if (item.Component is Button)
{
DesignItemProperty contentProperty = item.Properties["Content"];
if (contentProperty.ValueOnInstance == null)
{
contentProperty.SetValue(item.ComponentType.Name);
}
}
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
if (verticalAlignmentProperty.ValueOnInstance == null)
{
verticalAlignmentProperty.SetValue(VerticalAlignment.Center);
}
DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"];
if (horizontalAlignmentProperty.ValueOnInstance == null)
{
horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center);
}
}
}
[ExtensionFor(typeof(TextBlock))]
public class TextBlockInitializer : DefaultInitializer
{
public override void InitializeDefaults(DesignItem item)
{
DesignItemProperty textProperty = item.Properties["Text"];
if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "")
{
textProperty.SetValue(item.ComponentType.Name);
}
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
if (verticalAlignmentProperty.ValueOnInstance == null)
{
verticalAlignmentProperty.SetValue(VerticalAlignment.Center);
}
DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"];
if (horizontalAlignmentProperty.ValueOnInstance == null)
{
horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center);
}
}
}
[ExtensionFor(typeof(HeaderedContentControl), OverrideExtension = typeof(ContentControlInitializer))]
public class HeaderedContentControlInitializer : DefaultInitializer
{

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MarginHandleExtension.cs

@ -85,6 +85,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -85,6 +85,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var leftMargin = position.Left - GetColumnOffset(column);
margin.Left = leftMargin;
this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].Reset();
this.ExtendedItem.Properties[FrameworkElement.WidthProperty].Reset();
}
} else {
if (_leftHandle.Visibility == Visibility.Visible) {
@ -111,6 +112,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -111,6 +112,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var topMargin = position.Top - GetRowOffset(row);
margin.Top = topMargin;
this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].Reset();
this.ExtendedItem.Properties[FrameworkElement.HeightProperty].Reset();
}
} else {
if (_topHandle.Visibility == Visibility.Visible) {
@ -137,6 +139,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -137,6 +139,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var rightMargin = GetColumnOffset(column + columnSpan) - position.Right;
margin.Right = rightMargin;
this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].Reset();
this.ExtendedItem.Properties[FrameworkElement.WidthProperty].Reset();
}
} else {
if (_rightHandle.Visibility == Visibility.Visible) {
@ -163,6 +166,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -163,6 +166,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var bottomMargin = GetRowOffset(row + rowSpan) - position.Bottom;
margin.Bottom = bottomMargin;
this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].Reset();
this.ExtendedItem.Properties[FrameworkElement.HeightProperty].Reset();
}
} else {
if (_bottomHandle.Visibility == Visibility.Visible) {

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

@ -64,6 +64,32 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -64,6 +64,32 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
[ExtensionFor(typeof(Border))]
public sealed class BorderInstanceFactory : CustomInstanceFactory
{
Brush _transparentBrush = new SolidColorBrush(Colors.Transparent);
/// <summary>
/// Creates an instance of the specified type, passing the specified arguments to its constructor.
/// </summary>
public override object CreateInstance(Type type, params object[] arguments)
{
object instance = base.CreateInstance(type, arguments);
Border panel = instance as Border;
if (panel != null)
{
if (panel.Background == null)
{
panel.Background = _transparentBrush;
}
TypeDescriptionProvider provider = new DummyValueInsteadOfNullTypeDescriptionProvider(
TypeDescriptor.GetProvider(panel), "Background", _transparentBrush);
TypeDescriptor.AddProvider(provider, panel);
}
return instance;
}
}
sealed class DummyValueInsteadOfNullTypeDescriptionProvider : TypeDescriptionProvider
{
// By using a TypeDescriptionProvider, we can intercept all access to the property that is

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelMove.cs

@ -14,6 +14,9 @@ using ICSharpCode.WpfDesign.Designer.Controls; @@ -14,6 +14,9 @@ using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionFor(typeof(Panel))]
[ExtensionFor(typeof(Border))]
[ExtensionFor(typeof(ContentControl))]
[ExtensionFor(typeof(Viewbox))]
public class PanelMove : PermanentAdornerProvider
{
protected override void OnInitialized()
@ -24,7 +27,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -24,7 +27,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var adorner = new PanelMoveAdorner(ExtendedItem);
AdornerPanel.SetPlacement(adorner, AdornerPlacement.FillContent);
adornerPanel.Children.Add(adorner);
Adorners.Add(adornerPanel);
Adorners.Add(adornerPanel);
}
}
}

128
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs

@ -0,0 +1,128 @@ @@ -0,0 +1,128 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class RasterPlacementBehavior : DefaultPlacementBehavior
{
int raster = 5;
Canvas surface;
AdornerPanel adornerPanel;
private bool rasterDrawn = false;
public override void BeginPlacement(PlacementOperation operation)
{
base.BeginPlacement(operation);
try {
raster = ((DesignPanel) ExtendedItem.Services.DesignPanel).RasterWidth;
}
catch (Exception ex)
{ }
CreateSurface(operation);
}
public override void EndPlacement(PlacementOperation operation)
{
base.EndPlacement(operation);
DeleteSurface();
}
public override void EnterContainer(PlacementOperation operation)
{
base.EnterContainer(operation);
CreateSurface(operation);
}
public override void LeaveContainer(PlacementOperation operation)
{
base.LeaveContainer(operation);
DeleteSurface();
}
void CreateSurface(PlacementOperation operation)
{
if (ExtendedItem.Services.GetService<IDesignPanel>() != null)
{
surface = new Canvas();
adornerPanel = new AdornerPanel();
adornerPanel.SetAdornedElement(ExtendedItem.View, ExtendedItem);
AdornerPanel.SetPlacement(surface, AdornerPlacement.FillContent);
adornerPanel.Children.Add(surface);
ExtendedItem.Services.DesignPanel.Adorners.Add(adornerPanel);
}
}
void DeleteSurface()
{
rasterDrawn = false;
if (surface != null)
{
ExtendedItem.Services.DesignPanel.Adorners.Remove(adornerPanel);
adornerPanel = null;
surface = null;
}
}
public override void BeforeSetPosition(PlacementOperation operation)
{
base.BeforeSetPosition(operation);
if (surface == null) return;
if (!((DesignPanel) ExtendedItem.Services.DesignPanel).UseRasterPlacement)
return;
if (Keyboard.IsKeyDown(Key.LeftCtrl))
{
surface.Children.Clear();
rasterDrawn = false;
return;
}
drawRaster();
var bounds = operation.PlacedItems[0].Bounds;
bounds.Y = ((int)bounds.Y/raster)*raster;
bounds.X = ((int)bounds.X/raster)*raster;
bounds.Width = Convert.ToInt32((bounds.Width/raster))*raster;
bounds.Height = Convert.ToInt32((bounds.Height/raster))*raster;
operation.PlacedItems[0].Bounds = bounds;
}
private void drawRaster()
{
if (!rasterDrawn)
{
rasterDrawn = true;
var w = ModelTools.GetWidth(ExtendedItem.View);
var h = ModelTools.GetHeight(ExtendedItem.View);
var dash = new DoubleCollection() {1, raster - 1};
for (int i = 0; i <= h; i += raster)
{
var line = new Line()
{
X1 = 0,
Y1 = i,
X2 = w,
Y2 = i,
StrokeThickness = 1,
Stroke = Brushes.Black,
StrokeDashArray = dash,
};
surface.Children.Add(line);
}
}
}
}
}

88
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RenderTransformOriginExtension.cs

@ -0,0 +1,88 @@ @@ -0,0 +1,88 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows;
using System.Windows.Input;
using ICSharpCode.WpfDesign.Designer.Controls;
using System.Windows.Media;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionFor(typeof(FrameworkElement))]
public class RenderTransformOriginExtension : SelectionAdornerProvider
{
readonly AdornerPanel adornerPanel;
RenderTransformOriginThumb renderTransformOriginThumb;
/// <summary>An array containing this.ExtendedItem as only element</summary>
readonly DesignItem[] extendedItemArray = new DesignItem[1];
IPlacementBehavior resizeBehavior;
PlacementOperation operation;
ChangeGroup changeGroup;
public RenderTransformOriginExtension()
{
adornerPanel = new AdornerPanel();
adornerPanel.Order = AdornerOrder.Foreground;
this.Adorners.Add(adornerPanel);
CreateRenderTransformOriginThumb();
}
void CreateRenderTransformOriginThumb()
{
renderTransformOriginThumb = new RenderTransformOriginThumb();
renderTransformOriginThumb.Cursor = Cursors.Hand;
AdornerPanel.SetPlacement(renderTransformOriginThumb,
new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top){XRelativeToContentWidth = renderTransformOrigin.X, YRelativeToContentHeight = renderTransformOrigin.Y});
adornerPanel.Children.Add(renderTransformOriginThumb);
renderTransformOriginThumb.DragDelta += new DragDeltaEventHandler(renderTransformOriginThumb_DragDelta);
}
void renderTransformOriginThumb_DragDelta(object sender, DragDeltaEventArgs e)
{
var p = AdornerPanel.GetPlacement(renderTransformOriginThumb) as RelativePlacement;
var pointAbs = adornerPanel.RelativeToAbsolute(new Vector(p.XRelativeToContentWidth, p.YRelativeToContentHeight));
var pointAbsNew = pointAbs + new Vector(e.HorizontalChange, e.VerticalChange);
var pRel = adornerPanel.AbsoluteToRelative(pointAbsNew);
AdornerPanel.SetPlacement(renderTransformOriginThumb,
new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top){ XRelativeToContentWidth = pRel.X, YRelativeToContentHeight = pRel.Y });
this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(pRel.X,pRel.Y));
}
Point renderTransformOrigin = new Point(0.5, 0.5);
protected override void OnInitialized()
{
base.OnInitialized();
extendedItemArray[0] = this.ExtendedItem;
this.ExtendedItem.PropertyChanged += OnPropertyChanged;
if (this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).IsSet) {
renderTransformOrigin = (Point)this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).ValueOnInstance;
}
AdornerPanel.SetPlacement(renderTransformOriginThumb,
new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top){XRelativeToContentWidth = renderTransformOrigin.X, YRelativeToContentHeight = renderTransformOrigin.Y});
}
void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ }
protected override void OnRemove()
{
base.OnRemove();
}
}
}

163
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs

@ -6,7 +6,7 @@ using System.Diagnostics; @@ -6,7 +6,7 @@ using System.Diagnostics;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
@ -26,8 +26,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -26,8 +26,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
readonly DesignItem[] extendedItemArray = new DesignItem[1];
IPlacementBehavior resizeBehavior;
PlacementOperation operation;
ChangeGroup changeGroup;
ChangeGroup changeGroup;
bool _isResizing;
/// <summary>
@ -78,41 +78,53 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -78,41 +78,53 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// <param name="alignment"></param>
/// <returns></returns>
private RelativePlacement Place(ref ResizeThumb resizeThumb,PlacementAlignment alignment)
{
RelativePlacement placement = new RelativePlacement(alignment.Horizontal,alignment.Vertical);
if (alignment.Horizontal == HorizontalAlignment.Center)
{
placement.WidthRelativeToContentWidth = 1;
placement.HeightOffset = 6;
resizeThumb.Opacity = 0;
return placement;
}
if (alignment.Vertical == VerticalAlignment.Center)
{
placement.HeightRelativeToContentHeight = 1;
placement.WidthOffset = 6;
resizeThumb.Opacity = 0;
return placement;
}
placement.WidthOffset = 6;
placement.HeightOffset = 6;
return placement;
}
{
RelativePlacement placement = new RelativePlacement(alignment.Horizontal,alignment.Vertical);
if (alignment.Horizontal == HorizontalAlignment.Center)
{
placement.WidthRelativeToContentWidth = 1;
placement.HeightOffset = 6;
resizeThumb.Opacity = 0;
return placement;
}
if (alignment.Vertical == VerticalAlignment.Center)
{
placement.HeightRelativeToContentHeight = 1;
placement.WidthOffset = 6;
resizeThumb.Opacity = 0;
return placement;
}
placement.WidthOffset = 6;
placement.HeightOffset = 6;
return placement;
}
Size oldSize;
ZoomControl zoom;
// TODO : Remove all hide/show extensions from here.
void drag_Started(DragListener drag)
{
var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
if (designPanel != null)
{
var p = VisualTreeHelper.GetParent(designPanel);
while (p != null && !(p is ZoomControl))
{
p = VisualTreeHelper.GetParent(p);
}
zoom = p as ZoomControl;
}
/* Abort editing Text if it was editing, because it interferes with the undo stack. */
foreach(var extension in this.ExtendedItem.Extensions){
if(extension is InPlaceEditorExtension){
((InPlaceEditorExtension)extension).AbortEdit();
}
}
oldSize = new Size(ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));
if (resizeBehavior != null)
operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
@ -134,11 +146,36 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -134,11 +146,36 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (alignment.Vertical == VerticalAlignment.Top) dy = -drag.Delta.Y;
if (alignment.Vertical == VerticalAlignment.Bottom) dy = drag.Delta.Y;
var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
if (zoom != null)
{
dx = dx * (1 / zoom.CurrentZoom);
dy = dy * (1 / zoom.CurrentZoom);
}
var newWidth = Math.Max(0, oldSize.Width + dx);
var newHeight = Math.Max(0, oldSize.Height + dy);
ModelTools.Resize(ExtendedItem, newWidth, newHeight);
if (operation.CurrentContainerBehavior is GridPlacementSupport)
{
var hor = (HorizontalAlignment)this.ExtendedItem.Properties[FrameworkElement.HorizontalAlignmentProperty].ValueOnInstance;
var ver = (VerticalAlignment)this.ExtendedItem.Properties[FrameworkElement.VerticalAlignmentProperty].ValueOnInstance;
if (hor == HorizontalAlignment.Stretch)
this.ExtendedItem.Properties[FrameworkElement.WidthProperty].Reset();
else
this.ExtendedItem.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth);
if (ver == VerticalAlignment.Stretch)
this.ExtendedItem.Properties[FrameworkElement.HeightProperty].Reset();
else
this.ExtendedItem.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight);
}
else
{
ModelTools.Resize(ExtendedItem, newWidth, newHeight);
}
if (operation != null) {
var info = operation.PlacedItems[0];
var result = info.OriginalBounds;
@ -167,7 +204,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -167,7 +204,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (drag.IsCanceled) changeGroup.Abort();
else changeGroup.Commit();
changeGroup = null;
}
}
_isResizing=false;
HideSizeAndShowHandles();
}
@ -213,43 +250,43 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -213,43 +250,43 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
void ShowSizeAndHideHandles()
{
SizeDisplayExtension sizeDisplay=null;
MarginHandleExtension marginDisplay=null;
foreach(var extension in ExtendedItem.Extensions) {
if (extension is SizeDisplayExtension)
sizeDisplay = extension as SizeDisplayExtension;
if (extension is MarginHandleExtension)
marginDisplay = extension as MarginHandleExtension;
}
{
SizeDisplayExtension sizeDisplay=null;
MarginHandleExtension marginDisplay=null;
foreach(var extension in ExtendedItem.Extensions) {
if (extension is SizeDisplayExtension)
sizeDisplay = extension as SizeDisplayExtension;
if (extension is MarginHandleExtension)
marginDisplay = extension as MarginHandleExtension;
}
if(sizeDisplay!=null) {
sizeDisplay.HeightDisplay.Visibility = Visibility.Visible;
sizeDisplay.WidthDisplay.Visibility = Visibility.Visible;
}
if(marginDisplay!=null)
marginDisplay.HideHandles();
}
if(sizeDisplay!=null) {
sizeDisplay.HeightDisplay.Visibility = Visibility.Visible;
sizeDisplay.WidthDisplay.Visibility = Visibility.Visible;
}
if(marginDisplay!=null)
marginDisplay.HideHandles();
}
void HideSizeAndShowHandles()
{
SizeDisplayExtension sizeDisplay = null;
MarginHandleExtension marginDisplay=null;
foreach (var extension in ExtendedItem.Extensions){
if (extension is SizeDisplayExtension)
sizeDisplay = extension as SizeDisplayExtension;
if (extension is MarginHandleExtension)
marginDisplay = extension as MarginHandleExtension;
}
void HideSizeAndShowHandles()
{
SizeDisplayExtension sizeDisplay = null;
MarginHandleExtension marginDisplay=null;
foreach (var extension in ExtendedItem.Extensions){
if (extension is SizeDisplayExtension)
sizeDisplay = extension as SizeDisplayExtension;
if (extension is MarginHandleExtension)
marginDisplay = extension as MarginHandleExtension;
}
if (sizeDisplay != null) {
sizeDisplay.HeightDisplay.Visibility = Visibility.Hidden;
sizeDisplay.WidthDisplay.Visibility = Visibility.Hidden;
}
if (marginDisplay !=null ) {
marginDisplay.ShowHandles();
}
}
if (sizeDisplay != null) {
sizeDisplay.HeightDisplay.Visibility = Visibility.Hidden;
sizeDisplay.WidthDisplay.Visibility = Visibility.Hidden;
}
if (marginDisplay !=null ) {
marginDisplay.ShowHandles();
}
}
}
}

176
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs

@ -0,0 +1,176 @@ @@ -0,0 +1,176 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
using System.Collections.Generic;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
/// The resize thumb around a component.
/// </summary>
[ExtensionFor(typeof(FrameworkElement))]
public sealed class RotateThumbExtension : SelectionAdornerProvider
{
readonly AdornerPanel adornerPanel;
readonly Thumb thumb;
/// <summary>An array containing this.ExtendedItem as only element</summary>
readonly DesignItem[] extendedItemArray = new DesignItem[1];
IPlacementBehavior resizeBehavior;
PlacementOperation operation;
ChangeGroup changeGroup;
bool _isResizing;
/// <summary>
/// Gets whether this extension is resizing any element.
/// </summary>
public bool IsResizing{
get { return _isResizing; }
}
public RotateThumbExtension()
{
adornerPanel = new AdornerPanel();
adornerPanel.Order = AdornerOrder.Foreground;
this.Adorners.Add(adornerPanel);
thumb = CreateRotateThumb();
}
ResizeThumb CreateRotateThumb()
{
ResizeThumb rotateThumb = new RotateThumb();
rotateThumb.Cursor = Cursors.Hand;
rotateThumb.Cursor = ZoomControl.GetCursor("Images/rotate.cur");
rotateThumb.Alignment = PlacementAlignment.Top;
AdornerPanel.SetPlacement(rotateThumb,
new RelativePlacement(HorizontalAlignment.Center, VerticalAlignment.Top) { WidthRelativeToContentWidth = 1, HeightOffset = 0 });
adornerPanel.Children.Add(rotateThumb);
DragListener drag = new DragListener(rotateThumb);
drag.Started += drag_Rotate_Started;
drag.Changed += drag_Rotate_Changed;
return rotateThumb;
}
Size oldSize;
#region Rotate
private Point centerPoint;
private UIElement parent;
private Vector startVector;
private RotateTransform rotateTransform;
private Point renderTransformOrigin;
private double initialAngle;
private DesignItem rtTransform;
private double angle;
private void drag_Rotate_Started(DragListener drag)
{
var designerItem = this.ExtendedItem.Component as FrameworkElement;
this.parent = VisualTreeHelper.GetParent(designerItem) as UIElement;
this.centerPoint = designerItem.TranslatePoint(
new Point(designerItem.ActualWidth*designerItem.RenderTransformOrigin.X,
designerItem.ActualHeight*designerItem.RenderTransformOrigin.Y),
this.parent);
Point startPoint = Mouse.GetPosition(this.parent);
this.startVector = Point.Subtract(startPoint, this.centerPoint);
if (this.rotateTransform == null)
{
this.initialAngle = 0;
}
else
{
this.initialAngle = this.rotateTransform.Angle;
}
rtTransform = this.ExtendedItem.Properties[FrameworkElement.RenderTransformProperty].Value;
operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
}
private void drag_Rotate_Changed(DragListener drag)
{
Point currentPoint = Mouse.GetPosition(this.parent);
Vector deltaVector = Point.Subtract(currentPoint, this.centerPoint);
double angle = Vector.AngleBetween(this.startVector, deltaVector);
var destAngle = this.initialAngle + Math.Round(angle, 0);
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
destAngle = ((int)destAngle / 15) * 15;
if (destAngle == 0)
{
this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Reset();
rtTransform = null;
rotateTransform = null;
}
else
{
if (rtTransform == null)
{
if (!this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).IsSet) {
this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5,0.5));
}
if (this.rotateTransform == null)
this.rotateTransform = new RotateTransform(0);
this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(rotateTransform);
rtTransform = this.ExtendedItem.Properties[FrameworkElement.RenderTransformProperty].Value;
}
rtTransform.Properties["Angle"].SetValue(destAngle);
this.angle = destAngle * Math.PI / 180.0;
}
}
#endregion
protected override void OnInitialized()
{
base.OnInitialized();
extendedItemArray[0] = this.ExtendedItem;
this.ExtendedItem.PropertyChanged += OnPropertyChanged;
this.Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged;
resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray);
OnPrimarySelectionChanged(null, null);
var designerItem = this.ExtendedItem.Component as FrameworkElement;
this.rotateTransform = designerItem.RenderTransform as RotateTransform;
if (rotateTransform != null)
angle = rotateTransform.Angle;
}
void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{ }
protected override void OnRemove()
{
this.ExtendedItem.PropertyChanged -= OnPropertyChanged;
this.Services.Selection.PrimarySelectionChanged -= OnPrimarySelectionChanged;
base.OnRemove();
}
void OnPrimarySelectionChanged(object sender, EventArgs e)
{
bool isPrimarySelection = this.Services.Selection.PrimarySelection == this.ExtendedItem;
foreach (RotateThumb g in adornerPanel.Children) {
g.IsPrimarySelection = isPrimarySelection;
}
}
}
}

11
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs

@ -19,7 +19,7 @@ using System.Windows.Input; @@ -19,7 +19,7 @@ using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class SnaplinePlacementBehavior : DefaultPlacementBehavior
public class SnaplinePlacementBehavior : RasterPlacementBehavior
{
AdornerPanel adornerPanel;
Canvas surface;
@ -59,6 +59,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -59,6 +59,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
base.BeforeSetPosition(operation);
if (surface == null) return;
if (!((DesignPanel)ExtendedItem.Services.DesignPanel).UseSnaplinePlacement)
return;
surface.Children.Clear();
if (Keyboard.IsKeyDown(Key.LeftCtrl)) return;
@ -167,6 +170,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -167,6 +170,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var containerRect = new Rect(0, 0, ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));
AddLines(containerRect, -Margin, false);
AddLines(containerRect, 0, false);
foreach (var item in ExtendedItem.ContentProperty.CollectionElements
.Except(operation.PlacedItems.Select(f => f.Item)))
{
@ -191,11 +196,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -191,11 +196,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (filter == null || filter.Value.Vertical == VerticalAlignment.Top)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Top - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Vertical == VerticalAlignment.Bottom)
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom, Start = r.Left, End = r.Right });
h.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Bottom - 1, Start = r.Left, End = r.Right });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Left)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Left - 1, Start = r.Top, End = r.Bottom });
if (filter == null || filter.Value.Horizontal == HorizontalAlignment.Right)
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right, Start = r.Top, End = r.Bottom });
v.Add(new Snapline() { RequireOverlap = requireOverlap, Offset = r2.Right - 1, Start = r.Top, End = r.Bottom });
}
void AddBaseline(DesignItem item, Rect bounds, List<Snapline> list)

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandle.cs

@ -24,6 +24,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -24,6 +24,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
[ExtensionFor(typeof(Image))]
[ExtensionFor(typeof(MediaElement))]
[ExtensionFor(typeof(ItemsControl))]
[ExtensionFor(typeof(Border))]
[ExtensionFor(typeof(Viewbox))]
[ExtensionFor(typeof(ContentControl))]
public class TopLeftContainerDragHandle : AdornerProvider
{
/// <summary/>

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Raster.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/Snapline.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/events.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/eye_watch.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/group.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/group2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/properties.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 B

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/rotate.cur

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/sort.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

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

@ -5,6 +5,13 @@ using System; @@ -5,6 +5,13 @@ using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.IO;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Xps.Serialization;
namespace ICSharpCode.WpfDesign.Designer
{
@ -86,6 +93,9 @@ namespace ICSharpCode.WpfDesign.Designer @@ -86,6 +93,9 @@ namespace ICSharpCode.WpfDesign.Designer
if (selectionService.SelectionCount == 0 && !items.Contains(parent)) {
selectionService.SetSelectedComponents(new DesignItem[] { parent });
}
foreach (var designItem in items) {
designItem.Name = null;
}
operation.DeleteItemsAndCommit();
} catch {
operation.Abort();
@ -93,15 +103,56 @@ namespace ICSharpCode.WpfDesign.Designer @@ -93,15 +103,56 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
internal static void CreateVisualTree(this UIElement element)
{
try {
var fixedDoc = new FixedDocument();
var pageContent = new PageContent();
var fixedPage = new FixedPage();
fixedPage.Children.Add(element);
(pageContent as IAddChild).AddChild(fixedPage);
fixedDoc.Pages.Add(pageContent);
var f = new XpsSerializerFactory();
var w = f.CreateSerializerWriter(new MemoryStream());
w.Write(fixedDoc);
fixedPage.Children.Remove(element);
}
catch (Exception)
{ }
}
internal static Size GetDefaultSize(DesignItem createdItem)
{
var s = Metadata.GetDefaultSize(createdItem.ComponentType);
if (double.IsNaN(s.Width)) {
s.Width = GetWidth(createdItem.View);
}
if (double.IsNaN(s.Height)) {
s.Height = GetHeight(createdItem.View);
}
CreateVisualTree(createdItem.View);
var s = Metadata.GetDefaultSize(createdItem.ComponentType, false);
if (double.IsNaN(s.Width) && createdItem.View.DesiredSize.Width > 0)
{
s.Width = createdItem.View.DesiredSize.Width;
}
if (double.IsNaN(s.Height) && createdItem.View.DesiredSize.Height > 0)
{
s.Height = createdItem.View.DesiredSize.Width;
}
var newS = Metadata.GetDefaultSize(createdItem.ComponentType, true);
if (!(s.Width > 0))
s.Width = newS.Width;
if (!(s.Height > 0))
s.Height = newS.Height;
if (double.IsNaN(s.Width)) {
s.Width = GetWidth(createdItem.View);
}
if (double.IsNaN(s.Height)) {
s.Height = GetHeight(createdItem.View);
}
return s;
}

34
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/Outline.xaml

@ -6,10 +6,40 @@ @@ -6,10 +6,40 @@
<UserControl.Resources>
<Style TargetType="ToggleButton" x:Key="eyeStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Grid Background="Transparent" IsHitTestVisible="True">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CheckStates">
<VisualState x:Name="Checked">
<Storyboard>
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="eye" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="circle" Storyboard.TargetProperty="(UIElement.Visibility)">
<DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Unchecked"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Image x:Name="eye" Stretch="Uniform" Visibility="Hidden" Source="pack://application:,,,/ICSharpCode.WpfDesign.Designer;component/Images/eye_watch.png" />
<Ellipse Width="6" Height="6" Stroke="Black" StrokeThickness="1" x:Name="circle" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<HierarchicalDataTemplate DataType="{x:Type Default:OutlineNode}"
ItemsSource="{Binding Children}">
<Default:IconItem Icon="../Images/Tag.png"
Text="{Binding Name}" />
<DockPanel>
<ToggleButton Style="{StaticResource eyeStyle}" DockPanel.Dock="Right" Width="20" Margin="0,0,5,0" IsChecked="{Binding IsDesignTimeVisible}" />
<Default:IconItem Icon="../Images/Tag.png" Text="{Binding Name}" />
</DockPanel>
</HierarchicalDataTemplate>
</UserControl.Resources>

33
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNode.cs

@ -11,6 +11,9 @@ using System.Collections.ObjectModel; @@ -11,6 +11,9 @@ using System.Collections.ObjectModel;
using System.Collections;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.XamlDom;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer.OutlineView
{
@ -41,6 +44,12 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView @@ -41,6 +44,12 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
DesignItem = designItem;
UpdateChildren();
var hidden = designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).ValueOnInstance;
if (hidden != null && (bool) hidden == true) {
this._isDesignTimeVisible = false;
((FrameworkElement) this.DesignItem.Component).Visibility = Visibility.Hidden;
}
//TODO
DesignItem.NameChanged += new EventHandler(DesignItem_NameChanged);
DesignItem.PropertyChanged += new PropertyChangedEventHandler(DesignItem_PropertyChanged);
@ -80,6 +89,28 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView @@ -80,6 +89,28 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
}
}
}
bool _isDesignTimeVisible = true;
public bool IsDesignTimeVisible
{
get {
return _isDesignTimeVisible;
}
set {
_isDesignTimeVisible = value;
var ctl = DesignItem.Component as UIElement;
ctl.Visibility = _isDesignTimeVisible ? Visibility.Visible : Visibility.Hidden;
RaisePropertyChanged("IsDesignTimeVisible");
if (!value)
DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).SetValue(true);
else
DesignItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).Reset();
}
}
ObservableCollection<OutlineNode> children = new ObservableCollection<OutlineNode>();
@ -147,7 +178,7 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView @@ -147,7 +178,7 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
return false;
var operation = PlacementOperation.Start(nodes.Select(node => node.DesignItem).ToArray(), DummyPlacementType);
if (operation != null) {
bool canEnter = placementBehavior.CanEnterContainer(operation);
bool canEnter = placementBehavior.CanEnterContainer(operation, true);
operation.Abort();
return canEnter;
}

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineView.xaml

@ -107,12 +107,30 @@ @@ -107,12 +107,30 @@
Margin="{TemplateBinding Level, Converter={StaticResource LevelConverter}}"
IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" />
<Border x:Name="contentBorder"
HorizontalAlignment="Left">
HorizontalAlignment="Stretch">
<ContentPresenter x:Name="PART_Header"
ContentSource="Header" />
</Border>
</DockPanel>
<ItemsPresenter x:Name="itemsHost" />
<DockPanel.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Cut" />
<MenuItem Command="ApplicationCommands.Copy" />
<MenuItem Command="ApplicationCommands.Paste" />
<Separator />
<MenuItem Command="ApplicationCommands.Delete" />
</ContextMenu>
</DockPanel.ContextMenu>
<DockPanel.ToolTip>
<ToolTip Background="White">
<Rectangle Width="50" Height="50">
<Rectangle.Fill>
<VisualBrush Stretch="Uniform" Visual="{Binding DesignItem.View}" />
</Rectangle.Fill>
</Rectangle>
</ToolTip>
</DockPanel.ToolTip>
</DockPanel>
<ControlTemplate.Triggers>

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/GradientSlider.xaml.cs

@ -94,7 +94,8 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor @@ -94,7 +94,8 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
if (e.Property == BrushProperty) {
if (Brush != null) {
GradientStops = new BindingList<GradientStop>(Brush.GradientStops);
SelectedStop = GradientStops.FirstOrDefault();
if (SelectedStop == null)
SelectedStop = GradientStops.FirstOrDefault();
}
else {
GradientStops = null;

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyContextMenu.xaml

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
>
<MenuItem Header="Reset"
IsEnabled="{Binding IsSet}"
Click="Click_Reset" />
<MenuItem Header="Binding"
Click="Click_Binding" /><!--

624
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGrid.cs

@ -1,296 +1,328 @@ @@ -1,296 +1,328 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Threading;
using System.Globalization;
using ICSharpCode.WpfDesign.PropertyGrid;
using System.Windows.Threading;
using System.Diagnostics;
using System.Windows.Media;
using System.Windows;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
{
public class PropertyGrid : INotifyPropertyChanged
{
public PropertyGrid()
{
Categories = new ObservableCollection<Category>(new [] {
specialCategory,
popularCategory,
otherCategory,
attachedCategory
});
Events = new PropertyNodeCollection();
}
Category specialCategory = new Category("Special");
Category popularCategory = new Category("Popular");
Category otherCategory = new Category("Other");
Category attachedCategory = new Category("Attached");
Dictionary<MemberDescriptor, PropertyNode> nodeFromDescriptor = new Dictionary<MemberDescriptor, PropertyNode>();
public ObservableCollection<Category> Categories { get; private set; }
public PropertyNodeCollection Events { get; private set; }
PropertyGridTab currentTab;
public PropertyGridTab CurrentTab {
get {
return currentTab;
}
set {
currentTab = value;
RaisePropertyChanged("CurrentTab");
RaisePropertyChanged("NameBackground");
}
}
string filter;
public string Filter {
get {
return filter;
}
set {
filter = value;
Reload();
RaisePropertyChanged("Filter");
}
}
DesignItem singleItem;
public DesignItem SingleItem {
get {
return singleItem;
}
private set {
if (singleItem != null) {
singleItem.NameChanged -= singleItem_NameChanged;
}
singleItem = value;
if (singleItem != null) {
singleItem.NameChanged += singleItem_NameChanged;
}
RaisePropertyChanged("SingleItem");
RaisePropertyChanged("Name");
RaisePropertyChanged("IsNameEnabled");
IsNameCorrect = true;
}
}
void singleItem_NameChanged(object sender, EventArgs e)
{
RaisePropertyChanged("Name");
}
public string OldName {
get; private set;
}
public string Name {
get {
if (SingleItem != null) {
return SingleItem.Name;
}
return null;
}
set {
if (SingleItem != null) {
try {
if (string.IsNullOrEmpty(value)) {
OldName = null;
SingleItem.Name = null;
} else {
OldName = SingleItem.Name;
SingleItem.Name = value;
}
IsNameCorrect = true;
} catch {
IsNameCorrect = false;
}
RaisePropertyChanged("Name");
}
}
}
bool isNameCorrect = true;
public bool IsNameCorrect {
get {
return isNameCorrect;
}
set {
isNameCorrect = value;
RaisePropertyChanged("IsNameCorrect");
}
}
public bool IsNameEnabled {
get {
return SingleItem != null;
}
}
IEnumerable<DesignItem> selectedItems;
public IEnumerable<DesignItem> SelectedItems {
get {
return selectedItems;
}
set {
selectedItems = value;
RaisePropertyChanged("SelectedItems");
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(
delegate {
Reload();
}));
}
}
public void ClearFilter()
{
Filter = null;
}
void Reload()
{
Clear();
if (SelectedItems == null || SelectedItems.Count() == 0) return;
if (SelectedItems.Count() == 1) SingleItem = SelectedItems.First();
foreach (var md in GetDescriptors()) {
if (PassesFilter(md.Name))
AddNode(md);
}
}
void Clear()
{
foreach (var c in Categories) {
c.IsVisible = false;
foreach (var p in c.Properties) {
p.IsVisible = false;
}
}
foreach (var e in Events) {
e.IsVisible = false;
}
SingleItem = null;
}
List<MemberDescriptor> GetDescriptors()
{
List<MemberDescriptor> list = new List<MemberDescriptor>();
if (SelectedItems.Count() == 1) {
foreach (MemberDescriptor d in TypeHelper.GetAvailableProperties(SingleItem.Component)) {
list.Add(d);
}
foreach (MemberDescriptor d in TypeHelper.GetAvailableEvents(SingleItem.ComponentType)) {
list.Add(d);
}
} else {
foreach (MemberDescriptor d in TypeHelper.GetCommonAvailableProperties(SelectedItems.Select(t => t.Component))) {
list.Add(d);
}
}
return list;
}
bool PassesFilter(string name)
{
if (string.IsNullOrEmpty(Filter)) return true;
for (int i = 0; i < name.Length; i++) {
if (i == 0 || char.IsUpper(name[i])) {
if (string.Compare(name, i, Filter, 0, Filter.Length, true) == 0) {
return true;
}
}
}
return false;
}
void AddNode(MemberDescriptor md)
{
var designProperties = SelectedItems.Select(item => item.Properties.GetProperty(md)).ToArray();
if (!Metadata.IsBrowsable(designProperties[0])) return;
PropertyNode node;
if (nodeFromDescriptor.TryGetValue(md, out node)) {
node.Load(designProperties);
} else {
node = new PropertyNode();
node.Load(designProperties);
if (node.IsEvent) {
Events.AddSorted(node);
} else {
var cat = PickCategory(node);
cat.Properties.AddSorted(node);
node.Category = cat;
}
nodeFromDescriptor[md] = node;
}
node.IsVisible = true;
if (node.Category != null)
node.Category.IsVisible = true;
}
Category PickCategory(PropertyNode node)
{
if (Metadata.IsPopularProperty(node.FirstProperty)) return popularCategory;
if (node.FirstProperty.IsAttachedDependencyProperty()) return attachedCategory;
var typeName = node.FirstProperty.DeclaringType.FullName;
if (typeName.StartsWith("System.Windows.") || typeName.StartsWith("ICSharpCode.WpfDesign.Designer.Controls."))
return otherCategory;
return specialCategory;
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged(string name)
{
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion
//class CategoryNameComparer : IComparer<string>
//{
// public static CategoryNameComparer Instance = new CategoryNameComparer();
// public int Compare(string x, string y)
// {
// int i1 = Array.IndexOf(Metadata.CategoryOrder, x);
// if (i1 == -1) i1 = int.MaxValue;
// int i2 = Array.IndexOf(Metadata.CategoryOrder, y);
// if (i2 == -1) i2 = int.MaxValue;
// if (i1 == i2) return x.CompareTo(y);
// return i1.CompareTo(i2);
// }
//}
}
public enum PropertyGridTab
{
Properties,
Events
}
}
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Threading;
using System.Globalization;
using ICSharpCode.WpfDesign.PropertyGrid;
using System.Windows.Threading;
using System.Diagnostics;
using System.Windows.Media;
using System.Windows;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
{
public class PropertyGrid : INotifyPropertyChanged
{
public PropertyGrid()
{
Categories = new CategoriesCollection();
Categories.Add(specialCategory);
Categories.Add(popularCategory);
Categories.Add(otherCategory);
Categories.Add(attachedCategory);
Events = new PropertyNodeCollection();
}
Category specialCategory = new Category("Special");
Category popularCategory = new Category("Popular");
Category otherCategory = new Category("Other");
Category attachedCategory = new Category("Attached");
Dictionary<MemberDescriptor, PropertyNode> nodeFromDescriptor = new Dictionary<MemberDescriptor, PropertyNode>();
public CategoriesCollection Categories { get; private set; }
public PropertyNodeCollection Events { get; private set; }
private PropertyGridGroupMode _groupMode;
public PropertyGridGroupMode GroupMode
{
get { return _groupMode; }
set
{
if (_groupMode != value)
{
_groupMode = value;
RaisePropertyChanged("GroupMode");
Reload();
}
}
}
PropertyGridTab currentTab;
public PropertyGridTab CurrentTab {
get {
return currentTab;
}
set {
currentTab = value;
RaisePropertyChanged("CurrentTab");
RaisePropertyChanged("NameBackground");
}
}
string filter;
public string Filter {
get {
return filter;
}
set {
filter = value;
Reload();
RaisePropertyChanged("Filter");
}
}
DesignItem singleItem;
public DesignItem SingleItem {
get {
return singleItem;
}
private set {
if (singleItem != null) {
singleItem.NameChanged -= singleItem_NameChanged;
}
singleItem = value;
if (singleItem != null) {
singleItem.NameChanged += singleItem_NameChanged;
}
RaisePropertyChanged("SingleItem");
RaisePropertyChanged("Name");
RaisePropertyChanged("IsNameEnabled");
IsNameCorrect = true;
}
}
void singleItem_NameChanged(object sender, EventArgs e)
{
RaisePropertyChanged("Name");
}
public string OldName {
get; private set;
}
public string Name {
get {
if (SingleItem != null) {
return SingleItem.Name;
}
return null;
}
set {
if (SingleItem != null) {
try {
if (string.IsNullOrEmpty(value)) {
OldName = null;
SingleItem.Name = null;
} else {
OldName = SingleItem.Name;
SingleItem.Name = value;
}
IsNameCorrect = true;
} catch {
IsNameCorrect = false;
}
RaisePropertyChanged("Name");
}
}
}
bool isNameCorrect = true;
public bool IsNameCorrect {
get {
return isNameCorrect;
}
set {
isNameCorrect = value;
RaisePropertyChanged("IsNameCorrect");
}
}
public bool IsNameEnabled {
get {
return SingleItem != null;
}
}
IEnumerable<DesignItem> selectedItems;
public IEnumerable<DesignItem> SelectedItems {
get {
return selectedItems;
}
set {
selectedItems = value;
RaisePropertyChanged("SelectedItems");
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new Action(
delegate {
Reload();
}));
}
}
public void ClearFilter()
{
Filter = null;
}
void Reload()
{
Clear();
if (SelectedItems == null || SelectedItems.Count() == 0) return;
if (SelectedItems.Count() == 1) SingleItem = SelectedItems.First();
foreach (var md in GetDescriptors()) {
if (PassesFilter(md.Name))
AddNode(md);
}
}
void Clear()
{
foreach (var c in Categories) {
c.IsVisible = false;
foreach (var p in c.Properties) {
p.IsVisible = false;
}
}
foreach (var e in Events) {
e.IsVisible = false;
}
SingleItem = null;
}
List<MemberDescriptor> GetDescriptors()
{
List<MemberDescriptor> list = new List<MemberDescriptor>();
if (SelectedItems.Count() == 1) {
foreach (MemberDescriptor d in TypeHelper.GetAvailableProperties(SingleItem.Component)) {
list.Add(d);
}
foreach (MemberDescriptor d in TypeHelper.GetAvailableEvents(SingleItem.ComponentType)) {
list.Add(d);
}
} else {
foreach (MemberDescriptor d in TypeHelper.GetCommonAvailableProperties(SelectedItems.Select(t => t.Component))) {
list.Add(d);
}
}
return list;
}
bool PassesFilter(string name)
{
if (string.IsNullOrEmpty(Filter)) return true;
for (int i = 0; i < name.Length; i++) {
if (i == 0 || char.IsUpper(name[i])) {
if (string.Compare(name, i, Filter, 0, Filter.Length, true) == 0) {
return true;
}
}
}
return false;
}
void AddNode(MemberDescriptor md)
{
var designProperties = SelectedItems.Select(item => item.Properties.GetProperty(md)).ToArray();
if (!Metadata.IsBrowsable(designProperties[0])) return;
PropertyNode node;
if (nodeFromDescriptor.TryGetValue(md, out node)) {
node.Load(designProperties);
} else {
node = new PropertyNode();
node.Load(designProperties);
if (node.IsEvent) {
Events.AddSorted(node);
} else {
var cat = PickCategory(node);
cat.Properties.AddSorted(node);
node.Category = cat;
}
nodeFromDescriptor[md] = node;
}
node.IsVisible = true;
if (node.Category != null)
node.Category.IsVisible = true;
}
Category PickCategory(PropertyNode node)
{
if (Metadata.IsPopularProperty(node.FirstProperty)) return popularCategory;
if (node.FirstProperty.IsAttachedDependencyProperty()) return attachedCategory;
var typeName = node.FirstProperty.DeclaringType.FullName;
if (typeName.StartsWith("System.Windows.") || typeName.StartsWith("ICSharpCode.WpfDesign.Designer.Controls."))
return otherCategory;
return specialCategory;
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged(string name)
{
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion
//class CategoryNameComparer : IComparer<string>
//{
// public static CategoryNameComparer Instance = new CategoryNameComparer();
// public int Compare(string x, string y)
// {
// int i1 = Array.IndexOf(Metadata.CategoryOrder, x);
// if (i1 == -1) i1 = int.MaxValue;
// int i2 = Array.IndexOf(Metadata.CategoryOrder, y);
// if (i2 == -1) i2 = int.MaxValue;
// if (i1 == i2) return x.CompareTo(y);
// return i1.CompareTo(i2);
// }
//}
}
public class CategoriesCollection : SortedObservableCollection<Category, string>
{
public CategoriesCollection()
: base(n => n.Name)
{
}
}
public enum PropertyGridGroupMode
{
GroupByPopularCategorys,
GroupByCategorys,
Ungrouped,
}
public enum PropertyGridTab
{
Properties,
Events
}
}

26
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGridView.xaml.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGridView.cs

@ -19,16 +19,29 @@ using ICSharpCode.WpfDesign.PropertyGrid; @@ -19,16 +19,29 @@ using ICSharpCode.WpfDesign.PropertyGrid;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
{
public partial class PropertyGridView
[TemplatePart(Name = "PART_Thumb", Type = typeof(Thumb))]
public class PropertyGridView : Control
{
static PropertyGridView()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(PropertyGridView), new FrameworkPropertyMetadata(typeof(PropertyGridView)));
}
public PropertyGridView()
{
PropertyGrid = new PropertyGrid();
DataContext = PropertyGrid;
InitializeComponent();
}
private Thumb thumb;
public override void OnApplyTemplate()
{
thumb = GetTemplateChild("PART_Thumb") as Thumb;
thumb.DragDelta += new DragDeltaEventHandler(thumb_DragDelta);
base.OnApplyTemplate();
}
static PropertyContextMenu propertyContextMenu = new PropertyContextMenu();
@ -37,7 +50,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid @@ -37,7 +50,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
public static readonly DependencyProperty FirstColumnWidthProperty =
DependencyProperty.Register("FirstColumnWidth", typeof(double), typeof(PropertyGridView),
new PropertyMetadata(120.0));
new PropertyMetadata(120.0));
public double FirstColumnWidth {
get { return (double)GetValue(FirstColumnWidthProperty); }
@ -77,11 +90,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid @@ -77,11 +90,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
contextMenu.IsOpen = true;
}
void clearButton_Click(object sender, RoutedEventArgs e)
{
PropertyGrid.ClearFilter();
}
void thumb_DragDelta(object sender, DragDeltaEventArgs e)
{
FirstColumnWidth = Math.Max(0, FirstColumnWidth + e.HorizontalChange);

578
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGridView.xaml

@ -1,356 +1,236 @@ @@ -1,356 +1,236 @@
<UserControl x:Class="ICSharpCode.WpfDesign.Designer.PropertyGrid.PropertyGridView"
x:Name="root"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters"
xmlns:PropertyGrid="clr-namespace:ICSharpCode.WpfDesign.Designer.PropertyGrid"
xmlns:PropertyGridBase="clr-namespace:ICSharpCode.WpfDesign.PropertyGrid;assembly=ICSharpCode.WpfDesign"
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls"
Background="{x:Static SystemColors.ControlLightBrush}"
SnapsToDevicePixels="True">
<UserControl.Resources>
<Style x:Key="ExpandButtonStyle"
TargetType="{x:Type ToggleButton}">
<Setter Property="Focusable"
Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Background="Transparent">
<Border Width="9"
Height="9"
SnapsToDevicePixels="true"
BorderBrush="#FF7898B5"
BorderThickness="1"
CornerRadius="1">
<Border.Background>
<LinearGradientBrush EndPoint="1,1"
StartPoint="0,0">
<GradientStop Color="White"
Offset=".2" />
<GradientStop Color="#FFC0B7A6"
Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Path Margin="1,1,1,1"
x:Name="ExpandPath"
Fill="Black"
Data="M 0 2 L 0 3 L 2 3 L 2 5 L 3 5 L 3 3 L 5 3 L 5 2 L 3 2 L 3 0 L 2 0 L 2 2 Z" />
</Border>
<ResourceDictionary xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters" xmlns:PropertyGrid="clr-namespace:ICSharpCode.WpfDesign.Designer.PropertyGrid" xmlns:PropertyGridBase="clr-namespace:ICSharpCode.WpfDesign.PropertyGrid;assembly=ICSharpCode.WpfDesign" xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls" xmlns:propertyGrid="clr-namespace:ICSharpCode.WpfDesign.Designer.PropertyGrid">
<Style x:Key="ExpandButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Focusable" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Background="Transparent">
<Border Width="9" Height="9" SnapsToDevicePixels="true" BorderBrush="#FF7898B5" BorderThickness="1" CornerRadius="1">
<Border.Background>
<LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
<GradientStop Color="White" Offset=".2" />
<GradientStop Color="#FFC0B7A6" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<Path Margin="1,1,1,1" x:Name="ExpandPath" Fill="Black" Data="M 0 2 L 0 3 L 2 3 L 2 5 L 3 5 L 3 3 L 5 3 L 5 2 L 3 2 L 3 0 L 2 0 L 2 2 Z" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked"
Value="True">
<Setter Property="Data"
TargetName="ExpandPath"
Value="M 0 2 L 0 3 L 5 3 L 5 2 Z" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="MoreButtonStyle"
TargetType="{x:Type ToggleButton}">
<Setter Property="Focusable"
Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Background="#F9F9F4"
BorderThickness="0 0 0 1"
BorderBrush="{x:Static SystemColors.ControlBrush}">
<!--<TextBlock Text="More..."
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Data" TargetName="ExpandPath" Value="M 0 2 L 0 3 L 5 3 L 5 2 Z" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="MoreButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Focusable" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border Background="#F9F9F4" BorderThickness="0 0 0 1" BorderBrush="{x:Static SystemColors.ControlBrush}">
<!--<TextBlock Text="More..."
VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="18 0 0 0"
Foreground="{x:Static SystemColors.ControlDarkBrush}" />-->
<Path x:Name="arrow"
Data="M 0 0 L 5 5 L 10 0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="{x:Static SystemColors.ControlDarkBrush}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked"
Value="True">
<Setter TargetName="arrow"
Property="Data"
Value="M 0 5 L 5 0 L 10 5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CategoryToggleStyle"
TargetType="{x:Type ToggleButton}">
<Setter Property="Focusable"
Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border BorderThickness="0 1 0 0"
BorderBrush="#ECE9D8">
<StackPanel Orientation="Horizontal"
Background="{x:Static SystemColors.ControlLightBrush}">
<ToggleButton Style="{StaticResource ExpandButtonStyle}"
IsChecked="{Binding IsExpanded}"
VerticalAlignment="Center"
Margin="3 0 7 0" />
<TextBlock Text="{Binding Name}"
VerticalAlignment="Center"
FontWeight="Bold"
Foreground="{x:Static SystemColors.ControlDarkBrush}" />
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CategoryExpanderStyle"
TargetType="Expander">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Expander">
<DockPanel>
<ToggleButton Height="17"
IsChecked="{Binding IsExpanded}"
DockPanel.Dock="Top"
Style="{StaticResource CategoryToggleStyle}" />
<ContentPresenter x:Name="ExpandSite"
Visibility="Collapsed" />
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded"
Value="True">
<Setter Property="Visibility"
Value="Visible"
TargetName="ExpandSite" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="MoreExpanderStyle"
TargetType="Expander">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Expander">
<DockPanel>
<ToggleButton IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource MoreButtonStyle}"
DockPanel.Dock="Top"
Height="12" />
<ContentPresenter x:Name="ExpandSite"
Visibility="Collapsed" />
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded"
Value="True">
<Setter Property="Visibility"
Value="Visible"
TargetName="ExpandSite" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<DataTemplate DataType="{x:Type PropertyGridBase:Category}">
<Expander Header="{Binding Name}"
Style="{StaticResource CategoryExpanderStyle}"
IsExpanded="{Binding IsExpanded}"
Visibility="{Binding IsVisible, Converter={x:Static Converters:CollapsedWhenFalse.Instance}}">
<ItemsControl ItemsSource="{Binding Properties}" />
<!--<StackPanel>
<ItemsControl ItemsSource="{Binding Properties}" />
<Expander Visibility="{Binding MoreProperties.Count, Converter={x:Static Converters:CollapsedWhenZero.Instance}}"
Style="{StaticResource MoreExpanderStyle}"
IsExpanded="{Binding ShowMore}">
<ItemsControl ItemsSource="{Binding MoreProperties}"
Background="#F9F9F4" />
</Expander>
</StackPanel>-->
</Expander>
</DataTemplate>
<DataTemplate DataType="{x:Type PropertyGridBase:PropertyNode}">
<StackPanel Visibility="{Binding IsVisible, Converter={x:Static Converters:CollapsedWhenFalse.Instance}}">
<Border x:Name="uxPropertyNodeRow"
MinHeight="20"
BorderThickness="0 0 0 1"
BorderBrush="{x:Static SystemColors.ControlBrush}"
DockPanel.Dock="Top">
<Path x:Name="arrow" Data="M 0 0 L 5 5 L 10 0" HorizontalAlignment="Center" VerticalAlignment="Center" Fill="{x:Static SystemColors.ControlDarkBrush}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="arrow" Property="Data" Value="M 0 5 L 5 0 L 10 5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CategoryToggleStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Focusable" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border BorderThickness="0 1 0 0" BorderBrush="#ECE9D8">
<StackPanel Orientation="Horizontal" Background="{x:Static SystemColors.ControlLightBrush}">
<ToggleButton Style="{StaticResource ExpandButtonStyle}" IsChecked="{Binding IsExpanded}" VerticalAlignment="Center" Margin="3 0 7 0" />
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" FontWeight="Bold" Foreground="{x:Static SystemColors.ControlDarkBrush}" />
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CategoryExpanderStyle" TargetType="Expander">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Expander">
<DockPanel>
<DockPanel Width="{Binding FirstColumnWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type PropertyGrid:PropertyGridView}}}"
DockPanel.Dock="Left">
<ToggleButton x:Name="expandButton"
DockPanel.Dock="Left"
Margin="{Binding Level, Converter={x:Static Converters:LevelConverter.Instance}}"
Style="{StaticResource ExpandButtonStyle}"
IsChecked="{Binding IsExpanded}"
Visibility="{Binding HasChildren, Converter={x:Static Converters:HiddenWhenFalse.Instance}}" />
<TextBlock Text="{Binding Name}"
TextTrimming="CharacterEllipsis"
VerticalAlignment="Center"
Margin="7 0 0 0"
ToolTip="{Binding Description}"
FontWeight="{Binding IsSet, Converter={x:Static Converters:BoldWhenTrue.Instance}}"
Foreground="{Binding NameForeground}" />
</DockPanel>
<Border BorderThickness="1 0 0 0"
BorderBrush="{x:Static SystemColors.ControlBrush}">
<ContentPresenter x:Name="editorContainer"
Content="{Binding Editor}"
VerticalAlignment="Center"
Margin="3 0" />
</Border>
<ToggleButton Height="17" IsChecked="{Binding IsExpanded}" DockPanel.Dock="Top" Style="{StaticResource CategoryToggleStyle}" />
<ContentPresenter x:Name="ExpandSite" Visibility="Collapsed" />
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter Property="Visibility" Value="Visible" TargetName="ExpandSite" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="MoreExpanderStyle" TargetType="Expander">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Expander">
<DockPanel>
<ToggleButton IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource MoreButtonStyle}" DockPanel.Dock="Top" Height="12" />
<ContentPresenter x:Name="ExpandSite" Visibility="Collapsed" />
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded" Value="True">
<Setter Property="Visibility" Value="Visible" TargetName="ExpandSite" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="SelectedImageButton" TargetType="{x:Type RadioButton}" BasedOn="{StaticResource {x:Type ToggleButton}}">
<Setter Property="BorderBrush" Value="Transparent" />
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="BorderBrush" Value="Blue" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderBrush" Value="DeepSkyBlue" />
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type PropertyGrid:PropertyGridView}">
<Setter Property="Background" Value="{x:Static SystemColors.ControlLightBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type PropertyGrid:PropertyGridView}">
<DockPanel LastChildFill="True" Background="{TemplateBinding Background}">
<DockPanel.Resources>
<DataTemplate DataType="{x:Type PropertyGridBase:Category}">
<Expander Header="{Binding Name}" Style="{StaticResource CategoryExpanderStyle}" IsExpanded="{Binding IsExpanded}" Visibility="{Binding IsVisible, Converter={x:Static Converters:CollapsedWhenFalse.Instance}}">
<ItemsControl ItemsSource="{Binding Properties}" />
</Expander>
</DataTemplate>
<DataTemplate DataType="{x:Type PropertyGridBase:PropertyNode}">
<StackPanel Visibility="{Binding IsVisible, Converter={x:Static Converters:CollapsedWhenFalse.Instance}}">
<Border x:Name="uxPropertyNodeRow" MinHeight="20" BorderThickness="0 0 0 1" BorderBrush="{x:Static SystemColors.ControlBrush}" DockPanel.Dock="Top">
<DockPanel>
<DockPanel Width="{Binding FirstColumnWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type PropertyGrid:PropertyGridView}}}" DockPanel.Dock="Left">
<ToggleButton x:Name="expandButton" DockPanel.Dock="Left" Margin="{Binding Level, Converter={x:Static Converters:LevelConverter.Instance}}" Style="{StaticResource ExpandButtonStyle}" IsChecked="{Binding IsExpanded}" Visibility="{Binding HasChildren, Converter={x:Static Converters:HiddenWhenFalse.Instance}}" />
<Rectangle Width="8" Height="8" Stroke="Black" Fill="{Binding IsSet, Converter={x:Static Converters:BlackWhenTrue.Instance}}" StrokeThickness="1" DockPanel.Dock="Right" Margin="4,0,4,0" VerticalAlignment="Center" />
<TextBlock Text="{Binding Name}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" Margin="7 0 0 0" ToolTip="{Binding Description}" FontWeight="{Binding IsSet, Converter={x:Static Converters:BoldWhenTrue.Instance}}" Foreground="{Binding NameForeground}" />
</DockPanel>
<Border BorderThickness="1 0 0 0" BorderBrush="{x:Static SystemColors.ControlBrush}">
<ContentPresenter x:Name="editorContainer" Content="{Binding Editor}" VerticalAlignment="Center" Margin="3 0" />
</Border>
</DockPanel>
</Border>
<StackPanel Visibility="{Binding IsExpanded, Converter={x:Static Converters:CollapsedWhenFalse.Instance}}">
<ItemsControl ItemsSource="{Binding Children}" Visibility="{Binding Children.Count, Converter={x:Static Converters:CollapsedWhenZero.Instance}}" />
<Expander Visibility="{Binding MoreChildren.Count, Converter={x:Static Converters:CollapsedWhenZero.Instance}}" Style="{StaticResource MoreExpanderStyle}">
<ItemsControl ItemsSource="{Binding MoreChildren}" Background="#F9F9F4" />
</Expander>
</StackPanel>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsEnabled}" Value="False">
<Setter TargetName="editorContainer" Property="Opacity" Value="0.5" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate DataType="{x:Type FontFamily}">
<TextBlock Text="{Binding}" Height="15" FontFamily="{Binding}" FontSize="12" />
</DataTemplate>
</DockPanel.Resources>
<Grid DockPanel.Dock="Top" Height="78">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Background="White" Grid.Column="0" BorderBrush="Black" BorderThickness="1" Width="44" Height="44" HorizontalAlignment="Left" Padding="2" Margin="6,0,0,0">
<Rectangle>
<Rectangle.Fill>
<VisualBrush Stretch="Uniform" Visual="{Binding SingleItem.Component}" />
</Rectangle.Fill>
</Rectangle>
</Border>
<TextBlock Grid.Column="1" Text="Name:" Margin="6,30,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
<TextBlock Grid.Column="1" Text="Type:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="6,8,0,0" />
<TextBlock Grid.Column="1" Text="Filter:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="6,54,0,0" />
<Controls:EnterTextBox Grid.Column="1" x:Name="NameTextBox" Text="{Binding Name}" IsEnabled="{Binding IsNameEnabled}" Margin="44,28,6,0" Height="19.277" VerticalAlignment="Top">
<Controls:EnterTextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsNameCorrect}" Value="False">
<Setter Property="BorderBrush" Value="Red" />
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsNameEnabled}" Value="True" />
<Condition Binding="{Binding CurrentTab}" Value="Events" />
<Condition Binding="{Binding Text, RelativeSource={RelativeSource Self}}" Value="" />
</MultiDataTrigger.Conditions>
<Setter Property="BorderBrush" Value="Red" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Controls:EnterTextBox.Style>
</Controls:EnterTextBox>
<TextBlock Grid.Column="1" Text="{Binding SingleItem.ComponentType.Name}" ToolTip="{Binding SingleItem.ComponentType}" Margin="44,8,6,0" Height="13.277" VerticalAlignment="Top" />
<Controls:ClearableTextBox Grid.Column="1" Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged}" Margin="44,52,6,0" VerticalAlignment="Top" Height="19" />
</Grid>
<Grid DockPanel.Dock="Top" Height="30">
<StackPanel Orientation="Horizontal">
<StackPanel Margin="3" HorizontalAlignment="Left" Orientation="Horizontal">
<RadioButton Style="{StaticResource SelectedImageButton}" GroupName="SortMode" IsChecked="{Binding GroupMode, Converter={x:Static Converters:EnumBoolean.Instance}, ConverterParameter=GroupByPopularCategorys}" Margin="3,0,0,0" Width="20" Height="20">
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/group.png" Stretch="None" />
</RadioButton>
<!--<RadioButton Style="{StaticResource SelectedImageButton}" GroupName="SortMode" IsChecked="{Binding GroupMode, Converter={x:Static Converters:EnumBoolean.Instance}, ConverterParameter=GroupByCategorys}" Margin="3,0,0,0" Width="20" Height="20">
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/group2.png" Stretch="None" />
</RadioButton>
<RadioButton Style="{StaticResource SelectedImageButton}" GroupName="SortMode" IsChecked="{Binding GroupMode, Converter={x:Static Converters:EnumBoolean.Instance}, ConverterParameter=Ungrouped}" Margin="3,0,0,0" Width="20" Height="20">
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/sort.png" Stretch="None" />
</RadioButton>-->
</StackPanel>
<StackPanel Margin="3" HorizontalAlignment="Left" Orientation="Horizontal" Visibility="{Binding ShowPropertiesEventsSelector, Converter={x:Static Converters:CollapsedWhenFalse.Instance}, ElementName=root}">
<RadioButton Style="{StaticResource SelectedImageButton}" GroupName="ShowType" IsChecked="{Binding CurrentTab, Converter={x:Static Converters:EnumBoolean.Instance}, ConverterParameter=Properties}" Margin="3,0,0,0" Width="20" Height="20">
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/properties.png" Stretch="None" />
</RadioButton>
<RadioButton Style="{StaticResource SelectedImageButton}" GroupName="ShowType" IsChecked="{Binding CurrentTab, Converter={x:Static Converters:EnumBoolean.Instance}, ConverterParameter=Events}" Margin="3,0,0,0" Width="20" Height="20">
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/events.png" Stretch="None" />
</RadioButton>
</StackPanel>
</StackPanel>
</Grid>
<Grid x:Name="c1" Background="White">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" Visibility="{Binding CurrentTab, Converter={x:Static Converters:EnumVisibility.Instance}, ConverterParameter=Properties}">
<ItemsControl ItemsSource="{Binding Categories}" />
</ScrollViewer>
<ScrollViewer HorizontalScrollBarVisibility="Disabled" Visibility="{Binding CurrentTab, Converter={x:Static Converters:EnumVisibility.Instance}, ConverterParameter=Events}">
<ItemsControl ItemsSource="{Binding Events}" />
</ScrollViewer>
<Thumb x:Name="PART_Thumb" HorizontalAlignment="Left" Width="4" Margin="-2 0 0 0" Cursor="SizeWE">
<Thumb.RenderTransform>
<TranslateTransform X="{Binding FirstColumnWidth, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" />
</Thumb.RenderTransform>
<Thumb.Template>
<ControlTemplate>
<Border Background="Transparent" />
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Grid>
</DockPanel>
</Border>
<StackPanel Visibility="{Binding IsExpanded, Converter={x:Static Converters:CollapsedWhenFalse.Instance}}">
<ItemsControl ItemsSource="{Binding Children}"
Visibility="{Binding Children.Count, Converter={x:Static Converters:CollapsedWhenZero.Instance}}" />
<Expander Visibility="{Binding MoreChildren.Count, Converter={x:Static Converters:CollapsedWhenZero.Instance}}"
Style="{StaticResource MoreExpanderStyle}">
<ItemsControl ItemsSource="{Binding MoreChildren}"
Background="#F9F9F4" />
</Expander>
</StackPanel>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsEnabled}"
Value="False">
<Setter TargetName="editorContainer"
Property="Opacity"
Value="0.5" />
<Setter TargetName="editorContainer"
Property="IsHitTestVisible"
Value="False" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<!--<DataTemplate DataType="{x:Type FontFamily}">
<TextBlock Text="{Binding}"
FontFamily="{Binding}"
FontSize="16"/>
</DataTemplate>-->
</UserControl.Resources>
<DockPanel>
<Grid DockPanel.Dock="Top"
Height="78">
<TextBlock Text="Name:"
Margin="6,30.275,0,33.948"
HorizontalAlignment="Left"
Width="32.033" />
<TextBlock Text="Type:"
VerticalAlignment="Top"
Margin="6.424,7.998,0,0"
Height="13.277" />
<TextBlock Text="Filter:"
HorizontalAlignment="Left"
Margin="6,53.553,0,0"
VerticalAlignment="Top" />
<Controls:EnterTextBox x:Name="NameTextBox"
x:FieldModifier="public"
Text="{Binding Name}"
IsEnabled="{Binding IsNameEnabled}"
Margin="44.033,27.275,6,0"
Height="19.277"
VerticalAlignment="Top">
<Control.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<DataTrigger Binding="{Binding IsNameCorrect}"
Value="False">
<Setter Property="BorderBrush"
Value="Red" />
</DataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsNameEnabled}"
Value="True" />
<Condition Binding="{Binding CurrentTab}"
Value="Events" />
<Condition Binding="{Binding Text, RelativeSource={RelativeSource Self}}"
Value="" />
</MultiDataTrigger.Conditions>
<Setter Property="BorderBrush"
Value="Red" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Control.Style>
</Controls:EnterTextBox>
<TextBlock Text="{Binding SingleItem.ComponentType.Name}"
ToolTip="{Binding SingleItem.ComponentType}"
Margin="44.033,7.998,6,0"
Height="13.277"
VerticalAlignment="Top" />
<Controls:EnterTextBox Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged}"
Margin="44.033,50.553,52,0"
VerticalAlignment="Top"
Height="19.277" />
<Button x:Name="clearButton"
Content="Clear"
Click="clearButton_Click"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Margin="0,49.552,6,0"
Height="21.277"
Width="40" />
</Grid>
<Controls:EnumBar Value="{Binding CurrentTab}"
Container="{Binding ElementName=c1}"
Margin="5 0 0 5"
DockPanel.Dock="Top">
<Controls:EnumBar.ButtonStyle>
<Style TargetType="ToggleButton">
<Setter Property="Width"
Value="70" />
</Style>
</Controls:EnumBar.ButtonStyle>
</Controls:EnumBar>
<Grid x:Name="c1"
Background="White">
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
<ItemsControl ItemsSource="{Binding Categories}" />
</ScrollViewer>
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
<ItemsControl ItemsSource="{Binding Events}" />
</ScrollViewer>
<Thumb x:Name="thumb"
HorizontalAlignment="Left"
Width="4"
Margin="-2 0 0 0"
Cursor="SizeWE">
<Thumb.RenderTransform>
<TranslateTransform X="{Binding FirstColumnWidth, ElementName=root}" />
</Thumb.RenderTransform>
<Thumb.Template>
<ControlTemplate>
<Border Background="Transparent" />
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Grid>
</DockPanel>
</UserControl>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs

@ -73,7 +73,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -73,7 +73,7 @@ namespace ICSharpCode.WpfDesign.Designer
throw new NotImplementedException();
}
public bool CanEnterContainer(PlacementOperation operation)
public bool CanEnterContainer(PlacementOperation operation, bool shouldAlwaysEnter)
{
return false;
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs

@ -128,7 +128,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -128,7 +128,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
}
IPlacementBehavior b = result.ModelHit.GetBehavior<IPlacementBehavior>();
if (b != null && b.CanEnterContainer(operation)) {
if (b != null && b.CanEnterContainer(operation, false)) {
operation.ChangeContainer(result.ModelHit);
return true;
}

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/SelectionService.cs

@ -156,6 +156,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -156,6 +156,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
if (PrimarySelectionChanged != null) {
PrimarySelectionChanged(this, EventArgs.Empty);
}
RaisePropertyChanged("PrimarySelection");
}
if (!_selectedComponents.SequenceEqual(prevSelectedItems)) {

155
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs

@ -0,0 +1,155 @@ @@ -0,0 +1,155 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Diagnostics;
using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer.ThumbnailView
{
public class ThumbnailView : Control, INotifyPropertyChanged
{
public DesignSurface DesignSurface
{
get { return (DesignSurface)GetValue(DesignSurfaceProperty); }
set { SetValue(DesignSurfaceProperty, value); }
}
public static readonly DependencyProperty DesignSurfaceProperty =
DependencyProperty.Register("DesignSurface", typeof(DesignSurface), typeof(ThumbnailView), new PropertyMetadata(OnDesignSurfaceChanged));
private static void OnDesignSurfaceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctl = d as ThumbnailView;
if (ctl.oldSurface != null)
ctl.oldSurface.LayoutUpdated -= ctl.DesignSurface_LayoutUpdated;
ctl.oldSurface = ctl.DesignSurface;
ctl.scrollViewer = null;
if (ctl.DesignSurface != null)
{
ctl.DesignSurface.LayoutUpdated += ctl.DesignSurface_LayoutUpdated;
}
ctl.OnPropertyChanged("ScrollViewer");
}
static ThumbnailView()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ThumbnailView), new FrameworkPropertyMetadata(typeof(ThumbnailView)));
}
public ScrollViewer ScrollViewer
{
get
{
if (DesignSurface != null && scrollViewer == null)
scrollViewer = DesignSurface.TryFindChild<ZoomControl>();
return scrollViewer;
}
}
void DesignSurface_LayoutUpdated(object sender, EventArgs e)
{
if (this.scrollViewer == null)
OnPropertyChanged("ScrollViewer");
if (this.scrollViewer != null)
{
double scale, xOffset, yOffset;
this.InvalidateScale(out scale, out xOffset, out yOffset);
this.zoomThumb.Width = scrollViewer.ViewportWidth * scale;
this.zoomThumb.Height = scrollViewer.ViewportHeight * scale;
Canvas.SetLeft(this.zoomThumb, xOffset + this.ScrollViewer.HorizontalOffset*scale);
Canvas.SetTop(this.zoomThumb, yOffset + this.ScrollViewer.VerticalOffset*scale);
}
}
private DesignSurface oldSurface;
private ZoomControl scrollViewer;
private Canvas zoomCanvas;
private Thumb zoomThumb;
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
this.zoomThumb = Template.FindName("PART_ZoomThumb", this) as Thumb;
this.zoomCanvas = Template.FindName("PART_ZoomCanvas", this) as Canvas;
this.zoomThumb.DragDelta += this.Thumb_DragDelta;
}
private void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
{
if (DesignSurface != null)
{
if (scrollViewer != null)
{
double scale, xOffset, yOffset;
this.InvalidateScale(out scale, out xOffset, out yOffset);
scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + e.HorizontalChange / scale);
scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + e.VerticalChange / scale);
}
}
}
private void InvalidateScale(out double scale, out double xOffset, out double yOffset)
{
var designedElement = this.DesignSurface.DesignContext.RootItem.Component as FrameworkElement;
var fac1 = designedElement.ActualWidth / zoomCanvas.ActualWidth;
var fac2 = designedElement.ActualHeight / zoomCanvas.ActualHeight;
// zoom canvas size
double x = this.zoomCanvas.ActualWidth;
double y = this.zoomCanvas.ActualHeight;
if (fac1 < fac2)
{
x = designedElement.ActualWidth / fac2;
xOffset = (zoomCanvas.ActualWidth - x) / 2;
yOffset = 0;
}
else
{
y = designedElement.ActualHeight / fac1;
xOffset = 0;
yOffset = (zoomCanvas.ActualHeight - y) / 2;
}
double w = designedElement.ActualWidth;
double h = designedElement.ActualHeight;
double scaleX = x / w;
double scaleY = y / h;
scale = (scaleX < scaleY) ? scaleX : scaleY;
xOffset += (x - scale * w) / 2;
yOffset += (y - scale * h) / 2;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}

43
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.xaml

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:thumbnailView="clr-namespace:ICSharpCode.WpfDesign.Designer.ThumbnailView">
<Style TargetType="{x:Type thumbnailView:ThumbnailView}">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Padding" Value="5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type thumbnailView:ThumbnailView}">
<Border CornerRadius="1"
ClipToBounds="True"
BorderThickness="1"
Background="#EEE"
BorderBrush="DimGray">
<Grid>
<Canvas Margin="{TemplateBinding Padding}" Name="PART_ZoomCanvas">
<Canvas.Background>
<VisualBrush Stretch="Uniform" Visual="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ScrollViewer.Content}" />
</Canvas.Background>
<Thumb Name="PART_ZoomThumb" Cursor="SizeAll">
<Thumb.Style>
<Style TargetType="Thumb">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Rectangle StrokeThickness="1" Stroke="Black" Fill="Transparent" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Thumb.Style>
</Thumb>
</Canvas>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

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

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.WpfDesign.Designer
{
/// <summary>
/// Description of Translations.
/// </summary>
public class Translations
{
private static Translations _instance;
public static Translations Instance {
get {
if (_instance == null)
_instance = new Translations();
return _instance;
} protected set {
_instance = value;
}
}
public virtual string PressAltText {
get {
return "Press \"Alt\" to Enter Container";
}
}
}
}

43
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -55,6 +55,9 @@ @@ -55,6 +55,9 @@
<SpecificVersion>False</SpecificVersion>
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="ReachFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@ -76,8 +79,13 @@ @@ -76,8 +79,13 @@
<Compile Include="..\..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Extensions\RenderTransformOriginExtension.cs" />
<Compile Include="Translations.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Controls\AdornerLayer.cs" />
<Compile Include="Controls\CanvasPositionHandle.cs" />
<Compile Include="Controls\ClearableTextBox.cs" />
<Compile Include="Controls\ContainerDragHandle.cs" />
<Compile Include="Controls\DropDownButton.cs" />
<Compile Include="Controls\EnterTextBox.cs" />
@ -85,6 +93,7 @@ @@ -85,6 +93,7 @@
<DependentUpon>EnumBar.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\EnumButton.cs" />
<Compile Include="Controls\InfoTextEnterArea.cs" />
<Compile Include="Controls\GrayOutDesignerExceptActiveArea.cs">
<SubType>Code</SubType>
</Compile>
@ -98,6 +107,7 @@ @@ -98,6 +107,7 @@
<Compile Include="Controls\PageClone.cs" />
<Compile Include="Controls\PanelMoveAdorner.cs" />
<Compile Include="Controls\QuickOperationMenu.cs" />
<Compile Include="Controls\RotateThumb.cs" />
<Compile Include="Controls\SelectionFrame.cs" />
<Compile Include="Controls\ErrorBalloon.cs" />
<Compile Include="Controls\ResizeThumb.cs" />
@ -109,15 +119,14 @@ @@ -109,15 +119,14 @@
<Compile Include="Converters.cs" />
<Compile Include="DesignCommand.cs" />
<Compile Include="DesignPanel.cs" />
<Compile Include="DesignSurface.xaml.cs">
<DependentUpon>DesignSurface.xaml</DependentUpon>
</Compile>
<Compile Include="DesignSurface.cs" />
<Compile Include="DragDropExceptionHandler.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="Extensions\CanvasPlacementSupport.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Extensions\BorderForInvisibleControl.cs" />
<Compile Include="Extensions\CanvasPositionExtension.cs" />
<Compile Include="Extensions\Initializers.cs" />
<Compile Include="Extensions\DefaultPlacementBehavior.cs">
<SubType>Code</SubType>
@ -127,6 +136,8 @@ @@ -127,6 +136,8 @@
<Compile Include="Extensions\InPlaceEditorExtension.cs" />
<Compile Include="Extensions\MarginHandleExtension.cs" />
<Compile Include="Extensions\QuickOperationMenuExtension.cs" />
<Compile Include="Extensions\RasterPlacementBehavior.cs" />
<Compile Include="Extensions\RotateThumbExtension.cs" />
<Compile Include="Extensions\SizeDisplayExtension.cs" />
<Compile Include="Extensions\SnaplinePlacementBehavior.cs">
<SubType>Code</SubType>
@ -190,9 +201,7 @@ @@ -190,9 +201,7 @@
<DependentUpon>PropertyContextMenu.xaml</DependentUpon>
</Compile>
<Compile Include="PropertyGrid\PropertyGrid.cs" />
<Compile Include="PropertyGrid\PropertyGridView.xaml.cs">
<DependentUpon>PropertyGridView.xaml</DependentUpon>
</Compile>
<Compile Include="PropertyGrid\PropertyGridView.cs" />
<Compile Include="RootItemBehavior.cs" />
<Compile Include="Services\ChooseClass.cs" />
<Compile Include="Services\ChooseClassDialog.xaml.cs">
@ -217,6 +226,7 @@ @@ -217,6 +226,7 @@
<Compile Include="Services\WpfTopLevelWindowService.cs" />
<Compile Include="Services\XamlErrorService.cs" />
<Compile Include="SharedInstances.cs" />
<Compile Include="ThumbnailView\ThumbnailView.cs" />
<Compile Include="Xaml\XamlEditOperations.cs" />
<Compile Include="Xaml\XamlLoadSettings.cs" />
<Compile Include="Xaml\XamlModelCollectionElementsCollection.cs" />
@ -228,6 +238,7 @@ @@ -228,6 +238,7 @@
<Resource Include="Images\Tag.png" />
</ItemGroup>
<ItemGroup>
<Page Include="ThumbnailView\ThumbnailView.xaml" />
<ProjectReference Include="..\..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
<Name>ICSharpCode.SharpDevelop.Widgets</Name>
@ -323,7 +334,27 @@ @@ -323,7 +334,27 @@
<Resource Include="Images\ZoomIn.png" />
<Resource Include="Images\ZoomOut.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\eye_watch.png" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="Configuration\CodeAnalysisDictionary.xml" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Raster.png" />
<Resource Include="Images\Snapline.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\rotate.cur" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\events.png" />
<Resource Include="Images\group.png" />
<Resource Include="Images\group2.png" />
<Resource Include="Images\properties.png" />
<Resource Include="Images\sort.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="ThumbnailView" />
</ItemGroup>
</Project>

23
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs

@ -5,6 +5,7 @@ using System; @@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Windows.Markup;
using System.Windows;
using ICSharpCode.WpfDesign.XamlDom;
@ -87,6 +88,28 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -87,6 +88,28 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
if (ComponentRegistered != null) {
ComponentRegistered(this, new DesignItemEventArgs(site));
}
if (_context.RootItem != null && !string.IsNullOrEmpty(site.Name)) {
var nameScope = _context.RootItem.Component as INameScope;
nameScope = NameScope.GetNameScope((DependencyObject) _context.RootItem.Component);
var fnd = nameScope.FindName(site.Name);
if (fnd != null) {
string newNm = site.Name + "_Copy";
fnd = nameScope.FindName(newNm);
if (fnd == null)
site.Name = newNm;
else {
int i = 1;
while (fnd != null) {
newNm = site.Name + "_Copy" + i;
fnd = nameScope.FindName(newNm);
i++;
}
site.Name = newNm;
}
}
}
return site;
}
}

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignContext.cs

@ -22,6 +22,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -22,6 +22,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
{
readonly XamlDocument _doc;
readonly XamlDesignItem _rootItem;
readonly XamlParserSettings _parserSettings;
internal readonly XamlComponentService _componentService;
readonly XamlEditOperations _xamlEditOperations;
@ -81,11 +82,11 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -81,11 +82,11 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
EditorManager.RegisterAssembly(designerAssembly);
}
XamlParserSettings parserSettings = new XamlParserSettings();
parserSettings.TypeFinder = loadSettings.TypeFinder;
parserSettings.CreateInstanceCallback = this.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory;
parserSettings.ServiceProvider = this.Services;
_doc = XamlParser.Parse(xamlReader, parserSettings);
_parserSettings = new XamlParserSettings();
_parserSettings.TypeFinder = loadSettings.TypeFinder;
_parserSettings.CreateInstanceCallback = this.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory;
_parserSettings.ServiceProvider = this.Services;
_doc = XamlParser.Parse(xamlReader, _parserSettings);
loadSettings.ReportErrors(xamlErrorService);
@ -106,7 +107,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -106,7 +107,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
}
_xamlEditOperations=new XamlEditOperations(this,parserSettings);
_xamlEditOperations=new XamlEditOperations(this,_parserSettings);
}
@ -125,6 +126,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -125,6 +126,13 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
get { return _rootItem; }
}
/// <summary>
/// Gets the parser Settings being used
/// </summary>
public XamlParserSettings ParserSettings {
get { return _parserSettings; }
}
/// <summary>
/// Opens a new change group used to batch several changes.
/// ChangeGroups work as transactions and are used to support the Undo/Redo system.

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs

@ -147,7 +147,15 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -147,7 +147,15 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
public override DesignItem Clone()
{
throw new NotImplementedException();
DesignItem item = null;
var xaml = XamlStaticTools.GetXaml(this.XamlObject);
XamlDesignItem rootItem = Context.RootItem as XamlDesignItem;
var obj = XamlParser.ParseSnippet(rootItem.XamlObject, xaml, ((XamlDesignContext) Context).ParserSettings);
if (obj != null)
{
item = ((XamlDesignContext)Context)._componentService.RegisterXamlComponentRecursive(obj);
}
return item;
}
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlEditOperations.cs

@ -161,7 +161,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -161,7 +161,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
void AddInParent(DesignItem parent,IList<DesignItem> pastedItems)
{
IEnumerable<Rect> rects = pastedItems.Select(i => new Rect(new Point(0, 0), new Point((double)i.Properties["Width"].ValueOnInstance, (double)i.Properties["Height"].ValueOnInstance)));
var operation = PlacementOperation.TryStartInsertNewComponents(parent, pastedItems, rects.ToList(), PlacementType.AddItem);
var operation = PlacementOperation.TryStartInsertNewComponents(parent, pastedItems, rects.ToList(), PlacementType.PasteItem);
ISelectionService selection = _context.Services.Selection;
selection.SetSelectedComponents(pastedItems);
if(operation!=null)

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/themes/generic.xaml

@ -3,5 +3,8 @@ @@ -3,5 +3,8 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ICSharpCode.WpfDesign.Designer;component/Controls/ControlStyles.xaml" />
<ResourceDictionary Source="/ICSharpCode.WpfDesign.Designer;component/OutlineView/OutlineView.xaml" />
<ResourceDictionary Source="/ICSharpCode.WpfDesign.Designer;component/DesignSurface.xaml" />
<ResourceDictionary Source="/ICSharpCode.WpfDesign.Designer;component/PropertyGrid/PropertyGridView.xaml" />
<ResourceDictionary Source="/ICSharpCode.WpfDesign.Designer;component/ThumbnailView/ThumbnailView.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

17
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/EditOperationTests.cs

@ -81,10 +81,23 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -81,10 +81,23 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
return grid;
}
private DesignItem IntializePasteOperationsCannotAddTest()
{
var grid = CreateGridContextWithDesignSurface("<Button Name=\"TestElement\"/><Grid><Image/></Grid><Window/><ListBox/>");
Assert.IsNotNull(grid);
var xamlConxtext = grid.Context as XamlDesignContext;
if (xamlConxtext != null) {
_name = grid.ContentProperty.CollectionElements[0].Name;
xamlConxtext.XamlEditAction.Cut(new[] {grid.ContentProperty.CollectionElements[0]});
} else
Assert.Fail();
return grid;
}
[Test]
public void PasteWhenContentControlSelectedAndCannotAdd()
{
var grid = IntializePasteOperationsTest();
var grid = IntializePasteOperationsCannotAddTest();
var xamlContext = grid.Context as XamlDesignContext;
Assert.IsNotNull(xamlContext);
@ -92,7 +105,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -92,7 +105,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
var innerGrid = grid.ContentProperty.CollectionElements[0];
selection.SetSelectedComponents(innerGrid.ContentProperty.CollectionElements);
xamlContext.XamlEditAction.Paste();
Assert.AreEqual(_name, innerGrid.ContentProperty.CollectionElements[1].Name);
Assert.AreEqual(_name, innerGrid.ContentProperty.CollectionElements[1].Name);
Assert.AreEqual(innerGrid.ContentProperty.CollectionElements[1], selection.PrimarySelection);
}

27
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/OutlineView/InsertTests.cs

@ -104,7 +104,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView @@ -104,7 +104,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView
}
[Test]
[Ignore]
//[Ignore]
public void CheckGridChildrenCountWhenCopy()
{
InsertIntoGridByCopy();
@ -113,7 +113,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView @@ -113,7 +113,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView
}
[Test]
[Ignore]
//[Ignore]
public void CheckStackPanelChildrenCountWhenCopy()
{
InsertIntoGridByCopy();
@ -122,25 +122,24 @@ namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView @@ -122,25 +122,24 @@ namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView
}
[Test]
[Ignore]
//[Ignore]
public void CheckElementsInOutlineWhenCopy()
{
InsertIntoGridByCopy();
Assert.AreEqual(_gridButtonNode, _outline.Children[0]);
Assert.AreEqual(_stackPanelButtonNode, _outline.Children[1]);
Assert.AreEqual(_stackPanelNode, _outline.Children[2]);
Assert.AreEqual(_stackPanelButtonNode, _stackPanelButtonNode.Children[0]);
Assert.AreEqual(_gridButtonNode.DesignItem.Component.GetType(), _outline.Children[0].DesignItem.Component.GetType());
Assert.AreEqual(_stackPanelButtonNode.DesignItem.Component.GetType(), _outline.Children[1].DesignItem.Component.GetType());
Assert.AreEqual(_stackPanelNode.DesignItem.Component.GetType(), _outline.Children[2].DesignItem.Component.GetType());
}
[Test]
[Ignore]
//[Ignore]
public void CheckElementsInDesignerWhenCopy()
{
InsertIntoGridByCopy();
Assert.AreEqual(_gridButton, _grid.ContentProperty.CollectionElements[0]);
Assert.AreEqual(_stackPanelButton, _grid.ContentProperty.CollectionElements[1]);
Assert.AreEqual(_stackPanel, _grid.ContentProperty.CollectionElements[2]);
Assert.AreEqual(_stackPanelButton, _stackPanel.ContentProperty.CollectionElements[0]);
Assert.AreEqual(_stackPanelButton.Component.GetType(), _grid.ContentProperty.CollectionElements[1].Component.GetType());
Assert.AreEqual(_stackPanel.Component.GetType(), _grid.ContentProperty.CollectionElements[2].Component.GetType());
Assert.AreEqual(_stackPanelButton.Component.GetType(), _stackPanel.ContentProperty.CollectionElements[0].Component.GetType());
}
#endregion
}
@ -177,11 +176,11 @@ namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView @@ -177,11 +176,11 @@ namespace ICSharpCode.WpfDesign.Tests.Designer.OutlineView
[Test]
public void CanInsertIntoButton()
{
/* Insert Image into the Grid's button. This has to be false since some of the
* ContentControl are not allowed to add element's by moving elements
/* Insert Image into the Grid's button. This has now to be true because a button can now
* add element's by moving elements
* See DefaultPlacementBehavior.CanContentControlAdd() */
Assert.IsFalse(_gridButtonNode.CanInsert(new[] {_stackPanelImageNode}, null, false));
Assert.IsTrue(_gridButtonNode.CanInsert(new[] {_stackPanelImageNode}, null, false));
}
#region Insert element by Cut operation.

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

@ -68,10 +68,12 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -68,10 +68,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
} else if (collectionInstance is ResourceDictionary) {
object val = newElement.GetValueFor(null);
object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null;
if (key == null) {
if (val is Style)
key = ((Style)val).TargetType;
}
//if (key == null || key == "") {
// if (val is Style)
// key = ((Style)val).TargetType;
//}
if (key == null || key == "")
key = val;
((ResourceDictionary)collectionInstance).Add(key, val);
} else {
collectionType.InvokeMember(

113
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/DesignTimeProperties.cs

@ -0,0 +1,113 @@ @@ -0,0 +1,113 @@
using System.Security.Cryptography;
using System.Windows;
namespace ICSharpCode.WpfDesign.XamlDom
{
/// <summary>
/// Helper Class for the Design Time Properties used by VS and Blend
/// </summary>
public class DesignTimeProperties : FrameworkElement
{
#region IsHidden
public static bool GetIsHidden(DependencyObject obj)
{
return (bool)obj.GetValue(IsHiddenProperty);
}
public static void SetIsHidden(DependencyObject obj, bool value)
{
obj.SetValue(IsHiddenProperty, value);
}
public static readonly DependencyProperty IsHiddenProperty =
DependencyProperty.RegisterAttached("IsHidden", typeof(bool), typeof(DesignTimeProperties));
#endregion
#region IsLocked
public static bool GetIsLocked(DependencyObject obj)
{
return (bool)obj.GetValue(IsLockedProperty);
}
public static void SetIsLocked(DependencyObject obj, bool value)
{
obj.SetValue(IsLockedProperty, value);
}
public static readonly DependencyProperty IsLockedProperty =
DependencyProperty.RegisterAttached("IsLocked", typeof(bool), typeof(DesignTimeProperties));
#endregion
#region DataContext
public static object GetDataContext(DependencyObject obj)
{
return (object)obj.GetValue(DataContextProperty);
}
public static void SetDataContext(DependencyObject obj, bool value)
{
obj.SetValue(DataContextProperty, value);
}
public static readonly DependencyProperty DataContextProperty =
DependencyProperty.RegisterAttached("DataContext", typeof(object), typeof(DesignTimeProperties));
#endregion
#region DesignSource
public static object GetDesignSource(DependencyObject obj)
{
return (object)obj.GetValue(DesignSourceProperty);
}
public static void SetDesignSource(DependencyObject obj, bool value)
{
obj.SetValue(DesignSourceProperty, value);
}
public static readonly DependencyProperty DesignSourceProperty =
DependencyProperty.RegisterAttached("DesignSource", typeof(object), typeof(DesignTimeProperties));
#endregion
#region DesignWidth
public static double GetDesignWidth(DependencyObject obj)
{
return (double)obj.GetValue(DesignWidthProperty);
}
public static void SetDesignWidth(DependencyObject obj, double value)
{
obj.SetValue(DesignWidthProperty, value);
}
public static readonly DependencyProperty DesignWidthProperty =
DependencyProperty.RegisterAttached("DesignWidth", typeof(double), typeof(DesignTimeProperties));
#endregion
#region DesignHeight
public static double GetDesignHeight(DependencyObject obj)
{
return (double)obj.GetValue(DesignHeightProperty);
}
public static void SetDesignHeight(DependencyObject obj, double value)
{
obj.SetValue(DesignHeightProperty, value);
}
public static readonly DependencyProperty DesignHeightProperty =
DependencyProperty.RegisterAttached("DesignHeight", typeof(double), typeof(DesignTimeProperties));
#endregion
}
}

28
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupCompatibilityProperties.cs

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
using System.Security.Cryptography;
using System.Windows;
namespace ICSharpCode.WpfDesign.XamlDom
{
/// <summary>
/// Helper Class for the Markup Compatibility Properties used by VS and Blend
/// </summary>
public class MarkupCompatibilityProperties : FrameworkElement
{
#region Ignorable
public static string GetIgnorable(DependencyObject obj)
{
return (string)obj.GetValue(IgnorableProperty);
}
public static void SetIgnorable(DependencyObject obj, string value)
{
obj.SetValue(IgnorableProperty, value);
}
public static readonly DependencyProperty IgnorableProperty =
DependencyProperty.RegisterAttached("Ignorable", typeof(string), typeof(MarkupCompatibilityProperties));
#endregion
}
}

186
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj

@ -1,92 +1,94 @@ @@ -1,92 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<ProjectGuid>{88DA149F-21B2-48AB-82C4-28FB6BDFD783}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.WpfDesign.XamlDom</RootNamespace>
<AssemblyName>ICSharpCode.WpfDesign.XamlDom</AssemblyName>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\..\..\Main\ICSharpCode.SharpDevelop.snk</AssemblyOriginatorKeyFile>
<DelaySign>False</DelaySign>
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
<RunCodeAnalysis>False</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Globalization#CA1303;-Microsoft.Performance#CA1800</CodeAnalysisRules>
<OutputPath>..\..\..\..\..\..\AddIns\DisplayBindings\WpfDesign\</OutputPath>
<DocumentationFile>..\..\..\..\..\..\AddIns\DisplayBindings\WpfDesign\ICSharpCode.WpfDesign.XamlDom.xml</DocumentationFile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SourceAnalysisOverrideSettingsFile>C:\Users\Daniel\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<Optimize>False</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="PresentationCore">
<Private>False</Private>
</Reference>
<Reference Include="PresentationFramework">
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase">
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="CollectionElementsCollection.cs" />
<Compile Include="CollectionSupport.cs" />
<Compile Include="IXamlErrorSink.cs" />
<Compile Include="MarkupExtensionParser.cs" />
<Compile Include="MarkupExtensionPrinter.cs" />
<Compile Include="NameScopeHelper.cs" />
<Compile Include="PositionXmlDocument.cs" />
<Compile Include="XamlConstants.cs" />
<Compile Include="XamlDocument.cs" />
<Compile Include="XamlLoadException.cs" />
<Compile Include="XamlObject.cs" />
<Compile Include="XamlObjectServiceProvider.cs" />
<Compile Include="XamlParser.cs" />
<Compile Include="XamlParserSettings.cs" />
<Compile Include="XamlProperty.cs" />
<Compile Include="XamlPropertyInfo.cs" />
<Compile Include="XamlPropertyValue.cs" />
<Compile Include="XamlStaticTools.cs" />
<Compile Include="XamlTextValue.cs" />
<Compile Include="XamlTypeFinder.cs" />
<Compile Include="XamlTypeResolverProvider.cs" />
</ItemGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<ProjectGuid>{88DA149F-21B2-48AB-82C4-28FB6BDFD783}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.WpfDesign.XamlDom</RootNamespace>
<AssemblyName>ICSharpCode.WpfDesign.XamlDom</AssemblyName>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\..\..\Main\ICSharpCode.SharpDevelop.snk</AssemblyOriginatorKeyFile>
<DelaySign>False</DelaySign>
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
<RunCodeAnalysis>False</RunCodeAnalysis>
<CodeAnalysisRules>-Microsoft.Globalization#CA1303;-Microsoft.Performance#CA1800</CodeAnalysisRules>
<OutputPath>..\..\..\..\..\..\AddIns\DisplayBindings\WpfDesign\</OutputPath>
<DocumentationFile>..\..\..\..\..\..\AddIns\DisplayBindings\WpfDesign\ICSharpCode.WpfDesign.XamlDom.xml</DocumentationFile>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SourceAnalysisOverrideSettingsFile>C:\Users\Daniel\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<Optimize>False</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<PlatformTarget>AnyCPU</PlatformTarget>
<FileAlignment>4096</FileAlignment>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="PresentationCore">
<Private>False</Private>
</Reference>
<Reference Include="PresentationFramework">
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase">
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="CollectionElementsCollection.cs" />
<Compile Include="CollectionSupport.cs" />
<Compile Include="DesignTimeProperties.cs" />
<Compile Include="IXamlErrorSink.cs" />
<Compile Include="MarkupCompatibilityProperties.cs" />
<Compile Include="MarkupExtensionParser.cs" />
<Compile Include="MarkupExtensionPrinter.cs" />
<Compile Include="NameScopeHelper.cs" />
<Compile Include="PositionXmlDocument.cs" />
<Compile Include="XamlConstants.cs" />
<Compile Include="XamlDocument.cs" />
<Compile Include="XamlLoadException.cs" />
<Compile Include="XamlObject.cs" />
<Compile Include="XamlObjectServiceProvider.cs" />
<Compile Include="XamlParser.cs" />
<Compile Include="XamlParserSettings.cs" />
<Compile Include="XamlProperty.cs" />
<Compile Include="XamlPropertyInfo.cs" />
<Compile Include="XamlPropertyValue.cs" />
<Compile Include="XamlStaticTools.cs" />
<Compile Include="XamlTextValue.cs" />
<Compile Include="XamlTypeFinder.cs" />
<Compile Include="XamlTypeResolverProvider.cs" />
</ItemGroup>
</Project>

18
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlConstants.cs

@ -30,6 +30,18 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -30,6 +30,18 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary>
public const string PresentationNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
/// <summary>
/// The namespace used for the DesignTime schema.
/// Value: "http://schemas.microsoft.com/expression/blend/2008"
/// </summary>
public const string DesignTimeNamespace = "http://schemas.microsoft.com/expression/blend/2008";
/// <summary>
/// The namespace used for the MarkupCompatibility schema.
/// Value: "http://schemas.openxmlformats.org/markup-compatibility/2006"
/// </summary>
public const string MarkupCompatibilityNamespace = "http://schemas.openxmlformats.org/markup-compatibility/2006";
#endregion
#region Common property names
@ -40,6 +52,12 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -40,6 +52,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary>
public const string ResourcesPropertyName = "Resources";
/// <summary>
/// The name of xmlns.
/// Value: "xmlns"
/// </summary>
public const string Xmlns = "xmlns";
#endregion
}
}

131
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlDocument.cs

@ -5,6 +5,11 @@ using System; @@ -5,6 +5,11 @@ using System;
using System.ComponentModel;
using System.Windows.Markup;
using System.Xml;
using System.IO;
using System.Linq;
using System.Windows.Documents;
using System.Windows.Media;
using System.Collections.Generic;
namespace ICSharpCode.WpfDesign.XamlDom
{
@ -17,8 +22,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -17,8 +22,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlObject _rootElement;
IServiceProvider _serviceProvider;
XamlTypeFinder _typeFinder;
XamlTypeFinder _typeFinder;
int namespacePrefixCounter;
internal XmlDocument XmlDocument {
@ -166,17 +171,32 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -166,17 +171,32 @@ namespace ICSharpCode.WpfDesign.XamlDom
bool hasStringConverter = c.CanConvertTo(ctx, typeof(string)) && c.CanConvertFrom(typeof(string));
if (forProperty != null && hasStringConverter) {
return new XamlTextValue(this, c.ConvertToInvariantString(ctx, instance));
}
string ns = GetNamespaceFor(elementType);
string prefix = GetPrefixForNamespace(ns);
XmlElement xml = _xmlDoc.CreateElement(prefix, elementType.Name, ns);
if (hasStringConverter &&
XamlObject.GetContentPropertyName(elementType) != null)
{
}
string ns = GetNamespaceFor(elementType);
string prefix = GetPrefixForNamespace(ns);
XmlElement xml = _xmlDoc.CreateElement(prefix, elementType.Name, ns);
if (hasStringConverter && XamlObject.GetContentPropertyName(elementType) != null) {
xml.InnerText = c.ConvertToInvariantString(instance);
} else if (instance is Brush) { //Todo: this is a hacky fix, because Brush Editor don't edit Design Items and so we have no XML, only the Brush Object and we need to Parse the Brush to XAML!
var s = new MemoryStream();
XamlWriter.Save(instance, s);
s.Seek(0, SeekOrigin.Begin);
XmlDocument doc = new XmlDocument();
doc.Load(s);
xml = (XmlElement)_xmlDoc.ImportNode(doc.DocumentElement, true);
var attLst = xml.Attributes.Cast<XmlAttribute>().ToList();
foreach (XmlAttribute att in attLst) {
if (att.Name.StartsWith(XamlConstants.Xmlns)) {
var rootAtt = doc.DocumentElement.GetAttributeNode(att.Name);
if (rootAtt != null && rootAtt.Value == att.Value) {
xml.Attributes.Remove(att);
}
}
}
}
return new XamlObject(this, xml, elementType, instance);
@ -184,45 +204,56 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -184,45 +204,56 @@ namespace ICSharpCode.WpfDesign.XamlDom
internal string GetNamespaceFor(Type type)
{
if (type == typeof (DesignTimeProperties))
return XamlConstants.DesignTimeNamespace;
if (type == typeof (MarkupCompatibilityProperties))
return XamlConstants.MarkupCompatibilityNamespace;
return _typeFinder.GetXmlNamespaceFor(type.Assembly, type.Namespace);
}
internal string GetPrefixForNamespace(string @namespace)
{
if (@namespace == XamlConstants.PresentationNamespace)
{
return null;
}
string prefix = _xmlDoc.DocumentElement.GetPrefixOfNamespace(@namespace);
if (String.IsNullOrEmpty(prefix))
{
prefix = _typeFinder.GetPrefixForXmlNamespace(@namespace);
string existingNamespaceForPrefix = null;
if (!String.IsNullOrEmpty(prefix))
{
existingNamespaceForPrefix = _xmlDoc.DocumentElement.GetNamespaceOfPrefix(prefix);
}
if (String.IsNullOrEmpty(prefix) ||
!String.IsNullOrEmpty(existingNamespaceForPrefix) &&
existingNamespaceForPrefix != @namespace)
{
do
{
prefix = "Controls" + namespacePrefixCounter++;
} while (!String.IsNullOrEmpty(_xmlDoc.DocumentElement.GetNamespaceOfPrefix(prefix)));
}
string xmlnsPrefix = _xmlDoc.DocumentElement.GetPrefixOfNamespace(XamlConstants.XmlnsNamespace);
System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(xmlnsPrefix));
_xmlDoc.DocumentElement.SetAttribute(xmlnsPrefix + ":" + prefix, @namespace);
}
return prefix;
}
internal string GetPrefixForNamespace(string @namespace)
{
if (@namespace == XamlConstants.PresentationNamespace)
{
return null;
}
string prefix = _xmlDoc.DocumentElement.GetPrefixOfNamespace(@namespace);
if (String.IsNullOrEmpty(prefix))
{
prefix = _typeFinder.GetPrefixForXmlNamespace(@namespace);
string existingNamespaceForPrefix = null;
if (!String.IsNullOrEmpty(prefix))
{
existingNamespaceForPrefix = _xmlDoc.DocumentElement.GetNamespaceOfPrefix(prefix);
}
if (String.IsNullOrEmpty(prefix) ||
!String.IsNullOrEmpty(existingNamespaceForPrefix) &&
existingNamespaceForPrefix != @namespace)
{
do
{
prefix = "Controls" + namespacePrefixCounter++;
} while (!String.IsNullOrEmpty(_xmlDoc.DocumentElement.GetNamespaceOfPrefix(prefix)));
}
string xmlnsPrefix = _xmlDoc.DocumentElement.GetPrefixOfNamespace(XamlConstants.XmlnsNamespace);
System.Diagnostics.Debug.Assert(!String.IsNullOrEmpty(xmlnsPrefix));
_xmlDoc.DocumentElement.SetAttribute(xmlnsPrefix + ":" + prefix, @namespace);
if (@namespace == XamlConstants.DesignTimeNamespace)
{
var ignorableProp = new XamlProperty(this._rootElement,new XamlDependencyPropertyInfo(MarkupCompatibilityProperties.IgnorableProperty,true));
ignorableProp.SetAttribute(prefix);
}
}
return prefix;
}
}
}

37
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs

@ -105,7 +105,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -105,7 +105,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
XmlAttribute xmlAttribute;
internal XmlAttribute XmlAttribute {
internal XmlAttribute XmlAttribute {
get { return xmlAttribute; }
set {
xmlAttribute = value;
@ -113,9 +113,26 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -113,9 +113,26 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
static XmlElement VirtualAttachTo(XmlElement e, XmlElement target)
string GetPrefixOfNamespace(string ns, XmlElement target)
{
var prefix = target.GetPrefixOfNamespace(e.NamespaceURI);
var prefix = target.GetPrefixOfNamespace(ns);
if (!string.IsNullOrEmpty(prefix))
return prefix;
var obj = this;
while (obj != null)
{
prefix = obj.XmlElement.GetPrefixOfNamespace(ns);
if (!string.IsNullOrEmpty(prefix))
return prefix;
obj = obj.ParentObject;
}
return null;
}
XmlElement VirtualAttachTo(XmlElement e, XmlElement target)
{
var prefix = GetPrefixOfNamespace(e.NamespaceURI, target);
XmlElement newElement = e.OwnerDocument.CreateElement(prefix, e.LocalName, e.NamespaceURI);
foreach (XmlAttribute a in target.Attributes) {
@ -161,7 +178,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -161,7 +178,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
internal override void RemoveNodeFromParent()
{
{
if (XmlAttribute != null) {
XmlAttribute.OwnerElement.RemoveAttribute(XmlAttribute.Name);
xmlAttribute = null;
@ -170,7 +187,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -170,7 +187,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (!UpdateXmlAttribute(false, out holder)) {
element.ParentNode.RemoveChild(element);
}
}
}
//TODO: PropertyValue still there
//UpdateMarkupExtensionChain();
}
@ -182,7 +199,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -182,7 +199,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlObject holder;
if (!UpdateXmlAttribute(false, out holder)) {
if (holder != null &&
holder.XmlAttribute != null) {
holder.XmlAttribute != null) {
holder.XmlAttribute.OwnerElement.RemoveAttributeNode(holder.XmlAttribute);
holder.xmlAttribute = null;
holder.ParentProperty.AddChildNodeToProperty(holder.element);
@ -214,7 +231,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -214,7 +231,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
while (obj != null && obj.IsMarkupExtension && obj.ParentProperty != null) {
obj.ParentProperty.UpdateValueOnInstance();
obj = obj.ParentObject;
}
}
}
bool UpdateXmlAttribute(bool force, out XamlObject holder)
@ -291,7 +308,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -291,7 +308,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// </summary>
public string ContentPropertyName {
get {
return contentPropertyName;
return contentPropertyName;
}
}
@ -352,7 +369,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -352,7 +369,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
throw new ArgumentNullException("propertyName");
// if (propertyName == ContentPropertyName)
// return
// return
foreach (XamlProperty p in properties) {
if (!p.IsAttached && p.PropertyName == propertyName)
@ -479,7 +496,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -479,7 +496,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
object ProvideValue()
{
{
if (wrapper != null) {
return wrapper.ProvideValue();
}

59
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -9,6 +9,7 @@ using System.Diagnostics; @@ -9,6 +9,7 @@ using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Xml;
@ -137,7 +138,13 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -137,7 +138,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (attribute.NamespaceURI.Length > 0)
return attribute.NamespaceURI;
else
return attribute.OwnerElement.GetNamespaceOfPrefix("");
{
var ns = attribute.OwnerElement.GetNamespaceOfPrefix("");
if (string.IsNullOrEmpty(ns)) {
ns = XamlConstants.PresentationNamespace;
}
return ns;
}
}
readonly static object[] emptyObjectArray = new object[0];
@ -148,10 +155,13 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -148,10 +155,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
if (errorSink != null) {
var lineInfo = node as IXmlLineInfo;
var msg = x.Message;
if (x.InnerException != null)
msg += " (" + x.InnerException.Message + ")";
if (lineInfo != null) {
errorSink.ReportError(x.Message, lineInfo.LineNumber, lineInfo.LinePosition);
errorSink.ReportError(msg, lineInfo.LineNumber, lineInfo.LinePosition);
} else {
errorSink.ReportError(x.Message, 0, 0);
errorSink.ReportError(msg, 0, 0);
}
if (currentXamlObject != null) {
currentXamlObject.HasErrors = true;
@ -439,6 +449,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -439,6 +449,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
static XamlPropertyInfo GetPropertyInfo(object elementInstance, Type elementType, XmlAttribute attribute, XamlTypeFinder typeFinder)
{
var ret = GetXamlSpecialProperty(attribute);
if (ret != null)
return ret;
if (attribute.LocalName.Contains(".")) {
return GetPropertyInfo(typeFinder, elementInstance, elementType, GetAttributeNamespace(attribute), attribute.LocalName);
} else {
@ -446,6 +459,21 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -446,6 +459,21 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
internal static XamlPropertyInfo GetXamlSpecialProperty(XmlAttribute attribute)
{
if (attribute.LocalName == "Ignorable" && attribute.NamespaceURI == XamlConstants.MarkupCompatibilityNamespace) {
return FindAttachedProperty(typeof(MarkupCompatibilityProperties), attribute.LocalName);
} else if (attribute.LocalName == "DesignHeight" && attribute.NamespaceURI == XamlConstants.DesignTimeNamespace) {
return FindAttachedProperty(typeof(DesignTimeProperties), attribute.LocalName);
} else if (attribute.LocalName == "DesignWidth" && attribute.NamespaceURI == XamlConstants.DesignTimeNamespace) {
return FindAttachedProperty(typeof(DesignTimeProperties), attribute.LocalName);
} else if (attribute.LocalName == "IsHidden" && attribute.NamespaceURI == XamlConstants.DesignTimeNamespace) {
return FindAttachedProperty(typeof(DesignTimeProperties), attribute.LocalName);
}
return null;
}
internal static XamlPropertyInfo GetPropertyInfo(XamlTypeFinder typeFinder, object elementInstance, Type elementType, string xmlNamespace, string localName)
{
string typeName, propertyName;
@ -540,8 +568,10 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -540,8 +568,10 @@ namespace ICSharpCode.WpfDesign.XamlDom
XamlPropertyValue childValue = ParseValue(childNode);
if (childValue != null) {
if (propertyInfo.IsCollection) {
CollectionSupport.AddToCollection(propertyInfo.ReturnType, collectionInstance, childValue);
collectionProperty.ParserAddCollectionElement(element, childValue);
if (collectionInstance!=null) {
CollectionSupport.AddToCollection(propertyInfo.ReturnType, collectionInstance, childValue);
collectionProperty.ParserAddCollectionElement(element, childValue);
}
} else {
if (valueWasSet)
throw new XamlLoadException("non-collection property may have only one child element");
@ -594,6 +624,25 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -594,6 +624,25 @@ namespace ICSharpCode.WpfDesign.XamlDom
if(xmlnsAttribute!=null)
element.Attributes.Remove(xmlnsAttribute);
//Remove namespace Attributes defined in the Xaml Root from the Pasted Snippet!
List<XmlAttribute> removeAttributes = new List<XmlAttribute>();
foreach (XmlAttribute attrib in element.Attributes) {
if (attrib.Name.StartsWith("xmlns:")) {
var rootPrefix = root.OwnerDocument.GetPrefixForNamespace(attrib.Value);
if (rootPrefix == null) {
//todo: check if we can add to root, (maybe same ns exists)
root.OwnerDocument.XmlDocument.Attributes.Append((XmlAttribute)attrib.CloneNode(true));
removeAttributes.Add(attrib);
} else if (rootPrefix == attrib.Name.Substring(6)) {
removeAttributes.Add(attrib);
}
}
}
foreach (var removeAttribute in removeAttributes) {
element.Attributes.Remove(removeAttribute);
}
//end remove
XamlParser parser = new XamlParser();
parser.settings = settings;
parser.document = root.OwnerDocument;

42
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -124,7 +124,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -124,7 +124,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
/// <summary>
/// Gets if the property represents the FrameworkElement.Resources property that holds a locally-defined resource dictionary.
/// Gets if the property represents the FrameworkElement.Resources property that holds a locally-defined resource dictionary.
/// </summary>
public bool IsResources {
get { return isResources; }
@ -276,15 +276,15 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -276,15 +276,15 @@ namespace ICSharpCode.WpfDesign.XamlDom
obj.Properties.Where((prop) => prop.IsResources).FirstOrDefault() != null;
}
XmlElement CreatePropertyElement()
{
string ns = parentObject.OwnerDocument.GetNamespaceFor(parentObject.ElementType);
return parentObject.OwnerDocument.XmlDocument.CreateElement(
parentObject.OwnerDocument.GetPrefixForNamespace(ns),
parentObject.ElementType.Name + "." + this.PropertyName,
ns
);
}
XmlElement CreatePropertyElement()
{
string ns = parentObject.OwnerDocument.GetNamespaceFor(parentObject.ElementType);
return parentObject.OwnerDocument.XmlDocument.CreateElement(
parentObject.OwnerDocument.GetPrefixForNamespace(ns),
parentObject.ElementType.Name + "." + this.PropertyName,
ns
);
}
internal void AddChildNodeToProperty(XmlNode newChildNode)
{
@ -322,7 +322,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -322,7 +322,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (collection == null) {
if (collectionElements.Count == 0 && this.PropertyName != this.ParentObject.ContentPropertyName) {
// we have to create the collection element
_propertyElement = CreatePropertyElement();
_propertyElement = CreatePropertyElement();
if (this.IsResources) {
parentObject.XmlElement.PrependChild(_propertyElement);
@ -353,15 +353,19 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -353,15 +353,19 @@ namespace ICSharpCode.WpfDesign.XamlDom
string name;
var element = ParentObject.XmlElement;
if (IsAttached) {
name = PropertyTargetType.Name + "." + PropertyName;
if (IsAttached)
{
if (PropertyTargetType == typeof (DesignTimeProperties) || PropertyTargetType == typeof (MarkupCompatibilityProperties))
name = PropertyName;
else
name = PropertyTargetType.Name + "." + PropertyName;
string ns = ParentObject.OwnerDocument.GetNamespaceFor(PropertyTargetType);
string prefix = element.GetPrefixOfNamespace(ns);
string prefix = element.GetPrefixOfNamespace(ns);
if (String.IsNullOrEmpty(prefix)) {
prefix = ParentObject.OwnerDocument.GetPrefixForNamespace(ns);
}
prefix = ParentObject.OwnerDocument.GetPrefixForNamespace(ns);
}
if (!string.IsNullOrEmpty(prefix)) {
element.SetAttribute(name, ns, value);
@ -452,16 +456,16 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -452,16 +456,16 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (!String.IsNullOrEmpty(ParentObject.GetXamlAttribute("Name"))) {
throw new XamlLoadException("The property 'Name' is set more than once.");
}
string oldName = null;
string newName = null;
var oldTextValue = oldValue as XamlTextValue;
if (oldTextValue != null) oldName = oldTextValue.Text;
var newTextValue = newValue as XamlTextValue;
if (newTextValue != null) newName = newTextValue.Text;
NameScopeHelper.NameChanged(ParentObject, oldName, newName);
}
}

80
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs

@ -6,6 +6,8 @@ using System.Collections.Generic; @@ -6,6 +6,8 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Markup;
using System.Xaml;
using XamlReader = System.Windows.Markup.XamlReader;
namespace ICSharpCode.WpfDesign.XamlDom
{
@ -42,13 +44,13 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -42,13 +44,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
sealed class XamlNamespace
{
internal readonly string XmlNamespacePrefix;
{
internal readonly string XmlNamespacePrefix;
internal readonly string XmlNamespace;
internal XamlNamespace(string xmlNamespacePrefix, string xmlNamespace)
{
this.XmlNamespacePrefix = xmlNamespacePrefix;
{
this.XmlNamespacePrefix = xmlNamespacePrefix;
this.XmlNamespace = xmlNamespace;
}
@ -109,25 +111,22 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -109,25 +111,22 @@ namespace ICSharpCode.WpfDesign.XamlDom
} else {
return "clr-namespace:" + mapping.Namespace + ";assembly=" + mapping.Assembly.GetName().Name;
}
}
/// <summary>
/// Gets the prefix to use for the specified XML namespace,
/// or null if no suitable prefix could be found.
/// </summary>
public string GetPrefixForXmlNamespace(string xmlNamespace)
{
XamlNamespace ns;
if (namespaces.TryGetValue(xmlNamespace, out ns))
{
return ns.XmlNamespacePrefix;
}
else
{
return null;
}
}
}
/// <summary>
/// Gets the prefix to use for the specified XML namespace,
/// or null if no suitable prefix could be found.
/// </summary>
public string GetPrefixForXmlNamespace(string xmlNamespace)
{
XamlNamespace ns;
if (namespaces.TryGetValue(xmlNamespace, out ns)) {
return ns.XmlNamespacePrefix;
} else {
return null;
}
}
XamlNamespace ParseNamespace(string xmlNamespace)
{
@ -174,19 +173,19 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -174,19 +173,19 @@ namespace ICSharpCode.WpfDesign.XamlDom
public void RegisterAssembly(Assembly assembly)
{
if (assembly == null)
throw new ArgumentNullException("assembly");
Dictionary<string, string> namespacePrefixes = new Dictionary<string, string>();
foreach (XmlnsPrefixAttribute xmlnsPrefix in assembly.GetCustomAttributes(typeof(XmlnsPrefixAttribute), true)) {
namespacePrefixes.Add(xmlnsPrefix.XmlNamespace, xmlnsPrefix.Prefix);
}
throw new ArgumentNullException("assembly");
Dictionary<string, string> namespacePrefixes = new Dictionary<string, string>();
foreach (XmlnsPrefixAttribute xmlnsPrefix in assembly.GetCustomAttributes(typeof(XmlnsPrefixAttribute), true)) {
namespacePrefixes.Add(xmlnsPrefix.XmlNamespace, xmlnsPrefix.Prefix);
}
foreach (XmlnsDefinitionAttribute xmlnsDef in assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), true)) {
XamlNamespace ns;
if (!namespaces.TryGetValue(xmlnsDef.XmlNamespace, out ns)) {
string prefix;
namespacePrefixes.TryGetValue(xmlnsDef.XmlNamespace, out prefix);
ns = namespaces[xmlnsDef.XmlNamespace] = new XamlNamespace(prefix, xmlnsDef.XmlNamespace);
XamlNamespace ns;
if (!namespaces.TryGetValue(xmlnsDef.XmlNamespace, out ns)) {
string prefix;
namespacePrefixes.TryGetValue(xmlnsDef.XmlNamespace, out prefix);
ns = namespaces[xmlnsDef.XmlNamespace] = new XamlNamespace(prefix, xmlnsDef.XmlNamespace);
}
if (string.IsNullOrEmpty(xmlnsDef.AssemblyName)) {
AddMappingToNamespace(ns, new AssemblyNamespaceMapping(assembly, xmlnsDef.ClrNamespace));
@ -199,6 +198,17 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -199,6 +198,17 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
/// <summary>
/// Register the Namspaces not found in any Assembly, but used by VS and Expression Blend
/// </summary>
public void RegisterFixNamespaces()
{
var ns = namespaces[XamlConstants.DesignTimeNamespace] = new XamlNamespace("d", XamlConstants.DesignTimeNamespace);
AddMappingToNamespace(ns, new AssemblyNamespaceMapping(typeof(DesignTimeProperties).Assembly, typeof(DesignTimeProperties).Namespace));
ns = namespaces[XamlConstants.MarkupCompatibilityNamespace] = new XamlNamespace("mc", XamlConstants.MarkupCompatibilityNamespace);
AddMappingToNamespace(ns, new AssemblyNamespaceMapping(typeof(MarkupCompatibilityProperties).Assembly, typeof(MarkupCompatibilityProperties).Namespace));
}
/// <summary>
/// Load the assembly with the specified name.
/// You can override this method to implement custom assembly lookup.
@ -256,9 +266,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -256,9 +266,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
static WpfTypeFinder()
{
Instance = new XamlTypeFinder();
Instance.RegisterFixNamespaces();
Instance.RegisterAssembly(typeof(MarkupExtension).Assembly); // WindowsBase
Instance.RegisterAssembly(typeof(IAddChild).Assembly); // PresentationCore
Instance.RegisterAssembly(typeof(XamlReader).Assembly); // PresentationFramework
Instance.RegisterAssembly(typeof(XamlType).Assembly); // System.Xaml
}
}
}

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeResolverProvider.cs

@ -29,16 +29,32 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -29,16 +29,32 @@ namespace ICSharpCode.WpfDesign.XamlDom
XmlElement ContainingElement{
get { return containingObject.XmlElement; }
}
private string GetNamespaceOfPrefix(string prefix)
{
var ns = ContainingElement.GetNamespaceOfPrefix(prefix);
if (!string.IsNullOrEmpty(ns))
return ns;
var obj = containingObject;
while (obj != null)
{
ns = obj.XmlElement.GetNamespaceOfPrefix(prefix);
if (!string.IsNullOrEmpty(ns))
return ns;
obj = obj.ParentObject;
}
return null;
}
public Type Resolve(string typeName)
{
string typeNamespaceUri;
string typeLocalName;
if (typeName.Contains(":")) {
typeNamespaceUri = ContainingElement.GetNamespaceOfPrefix(typeName.Substring(0, typeName.IndexOf(':')));
typeNamespaceUri = GetNamespaceOfPrefix(typeName.Substring(0, typeName.IndexOf(':')));
typeLocalName = typeName.Substring(typeName.IndexOf(':') + 1);
} else {
typeNamespaceUri = ContainingElement.GetNamespaceOfPrefix("");
typeNamespaceUri = GetNamespaceOfPrefix("");
typeLocalName = typeName;
}
if (string.IsNullOrEmpty(typeNamespaceUri))

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Adorners/AdornerPanel.cs

@ -34,6 +34,16 @@ namespace ICSharpCode.WpfDesign.Adorners @@ -34,6 +34,16 @@ namespace ICSharpCode.WpfDesign.Adorners
return (AdornerPlacement)adorner.GetValue(PlacementProperty);
}
public Vector AbsoluteToRelative(Vector absolute)
{
return new Vector(absolute.X / ((FrameworkElement) this._adornedElement).ActualWidth, absolute.Y / ((FrameworkElement) this._adornedElement).ActualHeight);
}
public Vector RelativeToAbsolute(Vector relative)
{
return new Vector(relative.X * ((FrameworkElement) this._adornedElement).ActualWidth, relative.Y * ((FrameworkElement) this._adornedElement).ActualHeight);
}
/// <summary>
/// Sets the placement of the specified adorner.
/// </summary>

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs

@ -298,7 +298,7 @@ namespace ICSharpCode.WpfDesign @@ -298,7 +298,7 @@ namespace ICSharpCode.WpfDesign
/// Gets the default size for new controls of the specified type,
/// or new Size(double.NaN, double.NaN) if no default size was registered.
/// </summary>
public static Size GetDefaultSize(Type t)
public static Size GetDefaultSize(Type t, bool checkBasetype = true)
{
Size s;
lock (defaultSizes) {
@ -306,7 +306,7 @@ namespace ICSharpCode.WpfDesign @@ -306,7 +306,7 @@ namespace ICSharpCode.WpfDesign
if (defaultSizes.TryGetValue(t, out s)) {
return s;
}
t = t.BaseType;
t = checkBasetype ? t.BaseType : null;
}
}
return new Size(double.NaN, double.NaN);

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.WpfDesign @@ -57,7 +57,7 @@ namespace ICSharpCode.WpfDesign
/// <summary>
/// Gets if entering this container is allowed for the specified operation.
/// </summary>
bool CanEnterContainer(PlacementOperation operation);
bool CanEnterContainer(PlacementOperation operation, bool shouldAlwaysEnter);
/// <summary>
/// Let the placed children enter this container.

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementInformation.cs

@ -13,9 +13,9 @@ namespace ICSharpCode.WpfDesign @@ -13,9 +13,9 @@ namespace ICSharpCode.WpfDesign
{
/// <summary>
/// The designer rounds bounds to this number of digits to avoid floating point errors.
/// Value: 8
/// Value: 1
/// </summary>
public const int BoundsPrecision = 8;
public const int BoundsPrecision = 1;
Rect originalBounds, bounds;
readonly DesignItem item;

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

@ -246,7 +246,7 @@ namespace ICSharpCode.WpfDesign @@ -246,7 +246,7 @@ namespace ICSharpCode.WpfDesign
}
op.currentContainer = container;
op.currentContainerBehavior = container.GetBehavior<IPlacementBehavior>();
if (op.currentContainerBehavior == null || !op.currentContainerBehavior.CanEnterContainer(op)) {
if (op.currentContainerBehavior == null || !op.currentContainerBehavior.CanEnterContainer(op, true)) {
op.changeGroup.Abort();
return null;
}

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementType.cs

@ -35,6 +35,12 @@ namespace ICSharpCode.WpfDesign @@ -35,6 +35,12 @@ namespace ICSharpCode.WpfDesign
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly PlacementType Delete = Register("Delete");
/// <summary>
/// Inserting from Cliboard
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly PlacementType PasteItem = Register("PasteItem");
readonly string name;
private PlacementType(string name)

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/Editors/ComboBoxEditor.xaml

@ -7,4 +7,9 @@ @@ -7,4 +7,9 @@
Background="{x:Null}"
Focusable="False"
>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>

38
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs

@ -66,16 +66,32 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -66,16 +66,32 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
}
}
private static string[] hiddenPropertiesOnWindow = new[] {"ClipToBounds"};
/// <summary>
/// Gets available properties for an object, includes attached properties also.
/// </summary>
/// </summary>
public static IEnumerable<PropertyDescriptor> GetAvailableProperties(object element)
{
foreach(PropertyDescriptor p in TypeDescriptor.GetProperties(element)){
if (!p.IsBrowsable) continue;
if (p.IsReadOnly) continue;
if (p.Attributes.OfType<ObsoleteAttribute>().Count()!=0) continue;
yield return p;
if (element.GetType().FullName == "ICSharpCode.WpfDesign.Designer.Controls.WindowClone")
{
foreach (PropertyDescriptor p in TypeDescriptor.GetProperties(element))
{
if (!p.IsBrowsable) continue;
if (p.IsReadOnly) continue;
if (hiddenPropertiesOnWindow.Contains(p.Name)) continue;
if (p.Attributes.OfType<ObsoleteAttribute>().Count() != 0) continue;
yield return p;
}
}
else
{
foreach(PropertyDescriptor p in TypeDescriptor.GetProperties(element)){
if (!p.IsBrowsable) continue;
if (p.IsReadOnly) continue;
if (p.Attributes.OfType<ObsoleteAttribute>().Count()!=0) continue;
yield return p;
}
}
}
@ -98,11 +114,11 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -98,11 +114,11 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
/* Check if it is attached property.*/
if(pd1.Name.Contains(".") && pd2.Name.Contains(".")){
if(pd1.Name==pd2.Name){
typeOk=true;
break;
}
}
if(pd1.Name==pd2.Name){
typeOk=true;
break;
}
}
}
if (!typeOk) {
propertyOk = false;

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