Browse Source

Initial upload for XamlDesigner (successor of StandaloneDesigner).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3267 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Ivan Shumilin 17 years ago
parent
commit
493b4d0fe4
  1. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
  2. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs
  3. 69
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NumericUpDown.cs
  4. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NumericUpDown.xaml
  5. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ExtensionMethods.cs
  6. 35
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditor.cs
  7. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml.cs
  8. 17
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/PropertyGridView.xaml.cs
  9. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
  10. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/OptionService.cs
  11. 22
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/SelectionService.cs
  12. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/UndoService.cs
  13. 15
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelProperty.cs
  14. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionParser.cs
  15. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.sln
  16. 14
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/PropertyNode.cs
  17. 181
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/ActionManager.cs
  18. 22
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/App.xaml
  19. 37
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/App.xaml.cs
  20. 32
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/BitmapButton.xaml
  21. 45
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/BitmapButton.xaml.cs
  22. 33
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Configuration/AssemblyInfo.cs
  23. 110
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Configuration/Settings.Designer.cs
  24. 46
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Configuration/Settings.settings
  25. 51
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Configuration/app.config
  26. 29
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Configuration/app.manifest
  27. 53
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Converters.cs
  28. 212
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Document.cs
  29. 40
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/DocumentView.xaml
  30. 26
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/DocumentView.xaml.cs
  31. 57
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/DragListener.cs
  32. 93
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/ExtensionMethods.cs
  33. BIN
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Images/Reference.png
  34. BIN
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Images/Tag.png
  35. BIN
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Libraries/AvalonDock.dll
  36. BIN
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Libraries/ICSharpCode.TextEditor.dll
  37. 118
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/MainWindow.xaml
  38. 181
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/MainWindow.xaml.cs
  39. 71
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/MainWindow_Commands.cs
  40. 4
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/NewFileTemplate.xaml
  41. 107
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Outline.xaml
  42. 24
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Outline.xaml.cs
  43. 267
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/OutlineTree.cs
  44. 238
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Shell.cs
  45. 27
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/SimpleCommand.cs
  46. 31
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/TestFiles/1.xaml
  47. 41
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/TestFiles/2.xaml
  48. 101
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Toolbox.cs
  49. 43
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/ToolboxView.xaml
  50. 69
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/ToolboxView.xaml.cs
  51. 168
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/XamlDesigner.csproj
  52. 204
      src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/XamlFormatter.cs

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

@ -68,7 +68,11 @@ @@ -68,7 +68,11 @@
</Style>
<Style TargetType="{x:Type src:WindowClone}">
<Setter Property="Template">
<Setter Property="Width"
Value="640" />
<Setter Property="Height"
Value="480" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type src:WindowClone}">
<Border Background="{DynamicResource {x:Static SystemColors.GradientActiveCaptionBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1,1,1,1" CornerRadius="5,5,5,5">

38
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -30,11 +30,9 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -30,11 +30,9 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
static void PostProcessInput(object sender, ProcessInputEventArgs e)
{
if (CurrentListener != null)
{
if (CurrentListener != null) {
var a = e.StagingItem.Input as KeyEventArgs;
if (a != null && a.Key == Key.Escape)
{
if (a != null && a.Key == Key.Escape) {
Mouse.Capture(null);
CurrentListener.IsDown = false;
CurrentListener.Complete();
@ -48,32 +46,27 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -48,32 +46,27 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
CurrentPoint = StartPoint;
DeltaDelta = new Vector();
IsDown = true;
if (Started != null)
{
Started(this);
}
}
void Target_MouseMove(object sender, MouseEventArgs e)
{
if (IsDown)
{
if (IsDown) {
DeltaDelta = e.GetPosition(null) - CurrentPoint;
CurrentPoint += DeltaDelta;
if (!IsActive)
{
if (!IsActive) {
if (Math.Abs(Delta.X) >= SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(Delta.Y) >= SystemParameters.MinimumVerticalDragDistance)
{
Math.Abs(Delta.Y) >= SystemParameters.MinimumVerticalDragDistance) {
IsActive = true;
CurrentListener = this;
if (Started != null) {
Started(this);
}
}
}
if (IsActive && Changed != null)
{
if (IsActive && Changed != null) {
Changed(this);
}
}
@ -82,8 +75,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -82,8 +75,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
void Target_MouseUp(object sender, MouseButtonEventArgs e)
{
IsDown = false;
if (IsActive)
{
if (IsActive) {
Complete();
}
}
@ -93,8 +85,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -93,8 +85,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
IsActive = false;
CurrentListener = null;
if (Completed != null)
{
if (Completed != null) {
Completed(this);
}
}
@ -110,8 +101,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -110,8 +101,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public bool IsActive { get; private set; }
public bool IsDown { get; private set; }
public Vector Delta
{
public Vector Delta {
get { return CurrentPoint - StartPoint; }
}
}

69
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NumericUpDown.cs

@ -104,14 +104,22 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -104,14 +104,22 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
var upDrag = new DragListener(upButton);
var downDrag = new DragListener(downButton);
upDrag.Started += drag_Started;
upDrag.Changed += drag_Changed;
downDrag.Changed += drag_Changed;
upDrag.Completed += drag_Completed;
downDrag.Started += drag_Started;
downDrag.Changed += drag_Changed;
downDrag.Completed += drag_Completed;
Print();
}
void drag_Started(DragListener drag)
{
OnDragStarted();
}
void drag_Changed(DragListener drag)
{
IsDragging = true;
@ -121,6 +129,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -121,6 +129,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
void drag_Completed(DragListener drag)
{
IsDragging = false;
OnDragCompleted();
}
void downButton_Click(object sender, RoutedEventArgs e)
@ -133,6 +142,14 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -133,6 +142,14 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
if (!IsDragging) SmallUp();
}
protected virtual void OnDragStarted()
{
}
protected virtual void OnDragCompleted()
{
}
public void SmallUp()
{
MoveValue(SmallChange);
@ -153,37 +170,17 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -153,37 +170,17 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
MoveValue(-LargeChange);
}
public void Minimize()
{
Parse();
Value = Minimum;
}
public void Maximize()
{
Parse();
Value = Maximum;
}
void MoveValue(double delta)
{
Parse();
double result;
if (double.IsNaN(Value) || double.IsInfinity(Value)) {
SetValue(delta);
}
else {
SetValue(Value + delta);
}
}
void Parse()
{
double result;
if (double.TryParse(textBox.Text, out result)) {
SetValue(result);
else if (double.TryParse(textBox.Text, out result)) {
SetValue(result + delta);
}
else {
Print();
SetValue(Value + delta);
}
}
@ -199,15 +196,28 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -199,15 +196,28 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
//update: not derived from RangeBase - no problem
void SetValue(double newValue)
{
Value = (double)Math.Max(Minimum, Math.Min(newValue, Maximum));
Print();
newValue = CoerceValue(newValue);
if (Value != newValue) {
Value = newValue;
}
}
double CoerceValue(double newValue)
{
return Math.Max(Minimum, Math.Min(newValue, Maximum));
}
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
base.OnPreviewKeyDown(e);
if (e.Key == Key.Enter) {
Parse();
double result;
if (double.TryParse(textBox.Text, out result)) {
SetValue(result);
}
else {
Print();
}
textBox.SelectAll();
e.Handled = true;
}
@ -269,7 +279,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -269,7 +279,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
base.OnPropertyChanged(e);
if (e.Property == ValueProperty) {
SetValue((double)e.NewValue);
Value = CoerceValue((double)e.NewValue);
Print();
}
else if (e.Property == SmallChangeProperty &&
ReadLocalValue(LargeChangeProperty) == DependencyProperty.UnsetValue) {

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/NumericUpDown.xaml

@ -98,6 +98,8 @@ @@ -98,6 +98,8 @@
</Style>
<Style TargetType="{x:Type Controls:NumericUpDown}">
<Setter Property="Background"
Value="White" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="BorderBrush"

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

@ -10,13 +10,6 @@ namespace ICSharpCode.WpfDesign.Designer @@ -10,13 +10,6 @@ namespace ICSharpCode.WpfDesign.Designer
{
public static class ExtensionMethods
{
//public static T[] GetValues<T>(this Type type)
//{
// return type
// .GetProperties(BindingFlags.Static | BindingFlags.Public)
// .Select(p => p.GetValue(null, null)).OfType<T>().ToArray();
//}
public static double Coerce(this double d, double min, double max)
{
return Math.Max(Math.Min(d, max), min);

35
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditor.cs

@ -10,21 +10,6 @@ using System.Windows; @@ -10,21 +10,6 @@ using System.Windows;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
{
public enum BrushEditorKind
{
None,
Solid,
Linear,
Radial,
List
}
public class BrushItem
{
public string Name { get; set; }
public Brush Brush { get; set; }
}
public class BrushEditor : INotifyPropertyChanged
{
public BrushEditor()
@ -85,9 +70,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor @@ -85,9 +70,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
}
set {
if (property != null && property.Value != value) {
if (value != null && value.IsFrozen) {
value = value.Clone();
}
property.Value = value;
DetermineCurrentKind();
RaisePropertyChanged("Brush");
@ -189,7 +171,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor @@ -189,7 +171,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
public void Commit()
{
Property.Value = Property.Value;
Property.Value = Brush.Clone();
}
#region INotifyPropertyChanged Members
@ -205,4 +187,19 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor @@ -205,4 +187,19 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
#endregion
}
public enum BrushEditorKind
{
None,
Solid,
Linear,
Radial,
List
}
public class BrushItem
{
public string Name { get; set; }
public Brush Brush { get; set; }
}
}

13
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml.cs

@ -104,5 +104,18 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors @@ -104,5 +104,18 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
ClearValue(LargeChangeProperty);
}
}
ChangeGroup group;
protected override void OnDragStarted()
{
group = PropertyNode.FirstProperty.DesignItem.Context.OpenGroup("drag number",
PropertyNode.Properties.Select(p => p.DesignItem).ToArray());
}
protected override void OnDragCompleted()
{
group.Commit();
}
}
}

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

@ -40,6 +40,23 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid @@ -40,6 +40,23 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid
set { SetValue(FirstColumnWidthProperty, value); }
}
public static readonly DependencyProperty SelectedItemsProperty =
DependencyProperty.Register("SelectedItems", typeof(IEnumerable<DesignItem>), typeof(PropertyGridView));
public IEnumerable<DesignItem> SelectedItems
{
get { return (IEnumerable<DesignItem>)GetValue(SelectedItemsProperty); }
set { SetValue(SelectedItemsProperty, value); }
}
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property == SelectedItemsProperty) {
PropertyGrid.SelectedItems = SelectedItems;
}
}
void clearButton_Click(object sender, RoutedEventArgs e)
{
PropertyGrid.ClearFilter();

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs

@ -171,9 +171,9 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -171,9 +171,9 @@ namespace ICSharpCode.WpfDesign.Designer.Services
protected override void OnDragStarted(MouseEventArgs e)
{
operation = PlacementOperation.TryStartInsertNewComponents(container,
new DesignItem[] { createdItem },
new Rect[] { GetStartToEndRect(e) },
PlacementType.Resize);
new DesignItem[] { createdItem },
new Rect[] { GetStartToEndRect(e) },
PlacementType.Resize);
if (operation != null) {
services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
}

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

@ -17,6 +17,6 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -17,6 +17,6 @@ namespace ICSharpCode.WpfDesign.Designer.Services
/// <summary>
/// Gets/Sets whether the design surface should be grayed out while dragging/selection.
/// </summary>
public bool GrayOutDesignSurfaceExceptParentContainerWhenDragging = true;
public bool GrayOutDesignSurfaceExceptParentContainerWhenDragging = false;
}
}

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

@ -8,6 +8,8 @@ @@ -8,6 +8,8 @@
using System;
using System.Collections.Generic;
using System.Windows.Input;
using System.ComponentModel;
using System.Linq;
namespace ICSharpCode.WpfDesign.Designer.Services
{
@ -15,7 +17,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -15,7 +17,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
/// Manages the collection of selected components and the primary selection.
/// Notifies components with attached DesignSite when their selection state changes.
/// </summary>
sealed class DefaultSelectionService : ISelectionService
sealed class DefaultSelectionService : ISelectionService, INotifyPropertyChanged
{
HashSet<DesignItem> _selectedComponents = new HashSet<DesignItem>();
DesignItem _primarySelection;
@ -53,6 +55,8 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -53,6 +55,8 @@ namespace ICSharpCode.WpfDesign.Designer.Services
{
if (components == null)
components = SharedInstances.EmptyDesignItemArray;
if (_selectedComponents.SequenceEqual(components)) return;
if (SelectionChanging != null)
SelectionChanging(this, EventArgs.Empty);
@ -160,6 +164,22 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -160,6 +164,22 @@ namespace ICSharpCode.WpfDesign.Designer.Services
if (SelectionChanged != null) {
SelectionChanged(this, new DesignItemCollectionEventArgs(componentsToNotifyOfSelectionChange));
}
RaisePropertyChanged("SelectedItems");
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion
}
}

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/UndoService.cs

@ -8,6 +8,8 @@ @@ -8,6 +8,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.WpfDesign.Designer.Xaml;
namespace ICSharpCode.WpfDesign.Designer.Services
{
@ -75,6 +77,16 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -75,6 +77,16 @@ namespace ICSharpCode.WpfDesign.Designer.Services
{
AssertState(TransactionState.Open);
item.Do();
var a = item as XamlModelProperty.PropertyChangeAction;
if (a != null)
{
foreach (var b in items.OfType<XamlModelProperty.PropertyChangeAction>())
{
if (b.MergeWith(a)) return;
}
}
items.Add(item);
}

15
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelProperty.cs

@ -16,6 +16,7 @@ using System.Windows; @@ -16,6 +16,7 @@ using System.Windows;
namespace ICSharpCode.WpfDesign.Designer.Xaml
{
[DebuggerDisplay("XamlModelProperty: {Name}")]
sealed class XamlModelProperty : DesignItemProperty, IEquatable<XamlModelProperty>
{
readonly XamlDesignItem _designItem;
@ -213,7 +214,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -213,7 +214,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
}
}
sealed class PropertyChangeAction : ITransactionItem
public sealed class PropertyChangeAction : ITransactionItem
{
XamlModelProperty property;
@ -268,6 +269,18 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -268,6 +269,18 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
return new DesignItem[] { property._designItem };
}
}
public bool MergeWith(PropertyChangeAction other)
{
if (property._property == other.property._property)
{
newIsSet = other.newIsSet;
newValue = other.newValue;
newObject = other.newObject;
return true;
}
return false;
}
}
public override DesignItem DesignItem {

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionParser.cs

@ -237,6 +237,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -237,6 +237,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
string typeName = markupExtensionTokens[1].Value;
Type extensionType = typeResolver.Resolve(typeName + "Extension");
if (extensionType == null) extensionType = typeResolver.Resolve(typeName);
if (extensionType == null || !typeof(MarkupExtension).IsAssignableFrom(extensionType)) {
throw new XamlMarkupExtensionParseException("Unknown markup extension " + typeName + "Extension");
}

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.sln

@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfDesign.Tests", "WpfDesig @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfDesign.Tests", "WpfDesig
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfDesign.AddIn", "WpfDesign.AddIn\WpfDesign.AddIn.csproj", "{9A9D6FD4-6A2E-455D-ACC3-DDA775FE9865}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlDesigner", "XamlDesigner\XamlDesigner.csproj", "{27DA2B5C-2AAA-4478-AB00-3E184273C241}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -43,6 +45,10 @@ Global @@ -43,6 +45,10 @@ Global
{9A9D6FD4-6A2E-455D-ACC3-DDA775FE9865}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A9D6FD4-6A2E-455D-ACC3-DDA775FE9865}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A9D6FD4-6A2E-455D-ACC3-DDA775FE9865}.Release|Any CPU.Build.0 = Release|Any CPU
{27DA2B5C-2AAA-4478-AB00-3E184273C241}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27DA2B5C-2AAA-4478-AB00-3E184273C241}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27DA2B5C-2AAA-4478-AB00-3E184273C241}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27DA2B5C-2AAA-4478-AB00-3E184273C241}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

14
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/PropertyNode.cs

@ -19,7 +19,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -19,7 +19,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
PropertyNode(DesignItemProperty[] properties, PropertyNode parent)
{
this.properties = properties;
this.Properties = properties;
this.Parent = parent;
foreach (var property in properties) {
@ -40,14 +40,14 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -40,14 +40,14 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
static object Unset = new object();
DesignItemProperty[] properties;
public DesignItemProperty[] Properties { get; private set; }
bool raiseEvents = true;
public string Name { get { return FirstProperty.Name; } }
public bool IsEvent { get { return FirstProperty.IsEvent; } }
public ServiceContainer Services { get { return FirstProperty.DesignItem.Services; } }
public FrameworkElement Editor { get; private set; }
public DesignItemProperty FirstProperty { get { return properties[0]; } }
public DesignItemProperty FirstProperty { get { return Properties[0]; } }
public PropertyNode Parent { get; private set; }
public ObservableCollection<PropertyNode> Children { get; private set; }
@ -96,7 +96,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -96,7 +96,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
public bool IsSet {
get {
foreach (var p in properties) {
foreach (var p in Properties) {
if (p.IsSet) return true;
}
return false;
@ -111,7 +111,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -111,7 +111,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
public bool IsAmbiguous {
get {
foreach (var p in properties) {
foreach (var p in Properties) {
if (!object.Equals(p.ValueOnInstance, FirstProperty.ValueOnInstance)) {
return true;
}
@ -138,12 +138,12 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -138,12 +138,12 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
{
raiseEvents = false;
if (value == Unset) {
foreach (var p in properties) {
foreach (var p in Properties) {
p.Reset();
}
}
else {
foreach (var p in properties) {
foreach (var p in Properties) {
p.SetValue(value);
}
}

181
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/ActionManager.cs

@ -0,0 +1,181 @@ @@ -0,0 +1,181 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows.Documents;
using System.Windows.Controls.Primitives;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;
using System.Windows.Markup;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Threading;
namespace ICSharpCode.XamlDesigner
{
public enum DisableMode
{
Disable, Collapse
}
public class ActionArgs
{
public FrameworkElement Element { get; internal set; }
}
public delegate void ActionHandler(ActionArgs e);
public delegate bool CanActionHandler(ActionArgs e);
public class Action
{
public Action()
{
Elements = new List<FrameworkElement>();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Loaded, new System.Action(RegisterRequery));
}
void RegisterRequery()
{
CommandManager.RequerySuggested += new EventHandler(CommandManager_RequerySuggested);
}
void CommandManager_RequerySuggested(object sender, EventArgs e)
{
UpdateElements();
}
public string Text { get; set; }
public Shortcut Shortcut { get; set; }
public ImageSource IconSource { get; set; }
public DisableMode DisableMode { get; set; }
public event ActionHandler Executed;
public event CanActionHandler CanExecute;
public List<FrameworkElement> Elements { get; private set; }
public object ExecuteHost {
get {
if (Executed != null) return Executed.Target;
return null;
}
}
public void AttachTo(FrameworkElement f)
{
SetText(f);
SetShortcut(f);
SetIcon(f);
SetEvent(f);
Elements.Add(f);
}
public void UpdateElements()
{
if (CanExecute != null) {
foreach (var f in Elements) {
f.IsEnabled = CanExecute(new ActionArgs() { Element = f });
}
}
}
void SetText(FrameworkElement f)
{
if (Text == null) return;
if (f is ContentControl) {
(f as ContentControl).Content = Text;
}
else if (f is HeaderedItemsControl) {
(f as HeaderedItemsControl).Header = Text;
}
}
void SetShortcut(FrameworkElement f)
{
if (Shortcut == null) return;
if (f is MenuItem) {
(f as MenuItem).InputGestureText = Shortcut.ToString();
}
if (ExecuteHost == null) return;
(ExecuteHost as IInputElement).KeyDown += delegate(object sender, KeyEventArgs e) {
if (e.Key == Shortcut.Key && Keyboard.Modifiers == Shortcut.Modifiers) {
Executed(new ActionArgs() { Element = f });
}
};
}
void SetIcon(FrameworkElement f)
{
if (IconSource == null) return;
if (f is MenuItem) {
(f as MenuItem).Icon = new Image() { Source = IconSource };
}
}
void SetEvent(FrameworkElement f)
{
if (Executed == null) return;
f.PreviewMouseLeftButtonUp += delegate {
Executed(new ActionArgs() { Element = f });
};
}
}
public static class ActionManager
{
public static void SetAction(DependencyObject obj, object value)
{
Action a = value as Action;
if (a == null) {
if (obj is FrameworkElement) {
a = (Action)(obj as FrameworkElement).FindResource(value);
}
}
a.AttachTo(obj as FrameworkElement);
}
}
[TypeConverter(typeof(ShortcutConverter))]
public class Shortcut
{
public ModifierKeys Modifiers;
public Key Key;
static KeyConverter KeyConverter = new KeyConverter();
static ModifierKeysConverter ModifierKeysConverter = new ModifierKeysConverter();
public static Shortcut FromString(string s)
{
var result = new Shortcut();
var pos = s.LastIndexOf('+');
if (pos < 0) {
result.Key = (Key)KeyConverter.ConvertFromString(s);
}
else {
result.Modifiers = (ModifierKeys)ModifierKeysConverter.ConvertFromString(s.Substring(0, pos));
result.Key = (Key)KeyConverter.ConvertFromString(s.Substring(pos + 1));
}
return result;
}
public override string ToString()
{
if (Modifiers == ModifierKeys.None) return KeyConverter.ConvertToString(Key);
return ModifierKeysConverter.ConvertToString(Modifiers) + "+" + KeyConverter.ConvertToString(Key);
}
}
public class ShortcutConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return Shortcut.FromString((string)value);
}
}
}

22
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/App.xaml

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
<Application x:Class="ICSharpCode.XamlDesigner.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Converters="clr-namespace:ICSharpCode.XamlDesigner.Converters"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Converters:CollapsedWhenFalse x:Key="CollapsedWhenFalse" />
<Converters:FalseWhenZero x:Key="FalseWhenZero" />
<Style x:Key="TabButtonStyle"
TargetType="ToggleButton">
<Setter Property="Width"
Value="50" />
<Setter Property="ClickMode"
Value="Press" />
<Setter Property="Margin"
Value="3 3 0 3" />
</Style>
</Application.Resources>
</Application>

37
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/App.xaml.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using ICSharpCode.XamlDesigner.Configuration;
using System.Windows.Threading;
using System.Diagnostics;
namespace ICSharpCode.XamlDesigner
{
public partial class App
{
public static string[] Args;
protected override void OnStartup(StartupEventArgs e)
{
DispatcherUnhandledException += App_DispatcherUnhandledException;
Args = e.Args;
System.Windows.Forms.Application.EnableVisualStyles();
base.OnStartup(e);
}
void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Shell.ReportException(e.Exception);
e.Handled = true;
}
protected override void OnExit(ExitEventArgs e)
{
Settings.Default.Save();
base.OnExit(e);
}
}
}

32
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/BitmapButton.xaml

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
<Button x:Class="ICSharpCode.XamlDesigner.BitmapButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Focusable="False">
<Button.Template>
<ControlTemplate TargetType="Button">
<Image x:Name="image1"
Stretch="None"
Source="{Binding ImageNormal}" />
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Source"
Value="{Binding ImageHover}"
TargetName="image1" />
</Trigger>
<Trigger Property="IsPressed"
Value="True">
<Setter Property="Source"
Value="{Binding ImagePressed}"
TargetName="image1" />
</Trigger>
<Trigger Property="IsEnabled"
Value="False">
<Setter Property="Source"
Value="{Binding ImageDisabled}"
TargetName="image1" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>

45
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/BitmapButton.xaml.cs

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ICSharpCode.XamlDesigner
{
public partial class BitmapButton
{
public BitmapButton()
{
InitializeComponent();
DataContext = this;
}
public string ImageHover {
get { return "Images/" + GetType().Name + ".Hover.png"; }
}
public string ImageNormal {
get { return "Images/" + GetType().Name + ".Normal.png"; }
}
public string ImagePressed {
get { return "Images/" + GetType().Name + ".Pressed.png"; }
}
public string ImageDisabled {
get { return "Images/" + GetType().Name + ".Disabled.png"; }
}
}
class CloseButton : BitmapButton
{
}
}

33
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Configuration/AssemblyInfo.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("XamlDesigner")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

110
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Configuration/Settings.Designer.cs generated

@ -0,0 +1,110 @@ @@ -0,0 +1,110 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3031
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ICSharpCode.XamlDesigner.Configuration {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0,0,0,0")]
public global::System.Windows.Rect MainWindowRect {
get {
return ((global::System.Windows.Rect)(this["MainWindowRect"]));
}
set {
this["MainWindowRect"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(@"<DockingManager>
<ResizingPanel Orientation=""Horizontal"">
<ResizingPanel ResizeWidth=""200"" Orientation=""Vertical"">
<DockablePane ResizeHeight=""441.36166666666668"" Anchor=""Left"">
<DockableContent Name=""content1"" AutoHide=""false"" />
</DockablePane>
<DockablePane ResizeWidth=""200"" Anchor=""Left"">
<DockableContent Name=""content2"" AutoHide=""false"" />
</DockablePane>
</ResizingPanel>
<ResizingPanel Orientation=""Vertical"">
<DocumentPanePlaceHolder />
<DockablePane ResizeHeight=""138"" Anchor=""Bottom"">
<DockableContent Name=""content3"" AutoHide=""false"" />
</DockablePane>
</ResizingPanel>
<DockablePane ResizeWidth=""271"" Anchor=""Right"">
<DockableContent Name=""content4"" AutoHide=""false"" />
</DockablePane>
</ResizingPanel>
<Hidden />
<Windows />
</DockingManager>")]
public string AvalonDockLayout {
get {
return ((string)(this["AvalonDockLayout"]));
}
set {
this["AvalonDockLayout"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public global::System.Collections.Specialized.StringCollection RecentFiles {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["RecentFiles"]));
}
set {
this["RecentFiles"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(@"<?xml version=""1.0"" encoding=""utf-16""?>
<ArrayOfString xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<string>%ProgramFiles%\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll</string>
</ArrayOfString>")]
public global::System.Collections.Specialized.StringCollection AssemblyList {
get {
return ((global::System.Collections.Specialized.StringCollection)(this["AssemblyList"]));
}
set {
this["AssemblyList"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Maximized")]
public global::System.Windows.WindowState MainWindowState {
get {
return ((global::System.Windows.WindowState)(this["MainWindowState"]));
}
set {
this["MainWindowState"] = value;
}
}
}
}

46
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Configuration/Settings.settings

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="ICSharpCode.XamlDesigner.Configuration" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="MainWindowRect" Type="System.Windows.Rect" Scope="User">
<Value Profile="(Default)">0,0,0,0</Value>
</Setting>
<Setting Name="AvalonDockLayout" Type="System.String" Scope="User">
<Value Profile="(Default)">&lt;DockingManager&gt;
&lt;ResizingPanel Orientation="Horizontal"&gt;
&lt;ResizingPanel ResizeWidth="200" Orientation="Vertical"&gt;
&lt;DockablePane ResizeHeight="441.36166666666668" Anchor="Left"&gt;
&lt;DockableContent Name="content1" AutoHide="false" /&gt;
&lt;/DockablePane&gt;
&lt;DockablePane ResizeWidth="200" Anchor="Left"&gt;
&lt;DockableContent Name="content2" AutoHide="false" /&gt;
&lt;/DockablePane&gt;
&lt;/ResizingPanel&gt;
&lt;ResizingPanel Orientation="Vertical"&gt;
&lt;DocumentPanePlaceHolder /&gt;
&lt;DockablePane ResizeHeight="138" Anchor="Bottom"&gt;
&lt;DockableContent Name="content3" AutoHide="false" /&gt;
&lt;/DockablePane&gt;
&lt;/ResizingPanel&gt;
&lt;DockablePane ResizeWidth="271" Anchor="Right"&gt;
&lt;DockableContent Name="content4" AutoHide="false" /&gt;
&lt;/DockablePane&gt;
&lt;/ResizingPanel&gt;
&lt;Hidden /&gt;
&lt;Windows /&gt;
&lt;/DockingManager&gt;</Value>
</Setting>
<Setting Name="RecentFiles" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="AssemblyList" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;string&gt;%ProgramFiles%\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="MainWindowState" Type="System.Windows.WindowState" Scope="User">
<Value Profile="(Default)">Maximized</Value>
</Setting>
</Settings>
</SettingsFile>

51
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Configuration/app.config

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ICSharpCode.XamlDesigner.Configuration.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<ICSharpCode.XamlDesigner.Configuration.Settings>
<setting name="MainWindowRect" serializeAs="String">
<value>0,0,0,0</value>
</setting>
<setting name="AvalonDockLayout" serializeAs="String">
<value>&lt;DockingManager&gt;
&lt;ResizingPanel Orientation="Horizontal"&gt;
&lt;ResizingPanel ResizeWidth="200" Orientation="Vertical"&gt;
&lt;DockablePane ResizeHeight="441.36166666666668" Anchor="Left"&gt;
&lt;DockableContent Name="content1" AutoHide="false" /&gt;
&lt;/DockablePane&gt;
&lt;DockablePane ResizeWidth="200" Anchor="Left"&gt;
&lt;DockableContent Name="content2" AutoHide="false" /&gt;
&lt;/DockablePane&gt;
&lt;/ResizingPanel&gt;
&lt;ResizingPanel Orientation="Vertical"&gt;
&lt;DocumentPanePlaceHolder /&gt;
&lt;DockablePane ResizeHeight="138" Anchor="Bottom"&gt;
&lt;DockableContent Name="content3" AutoHide="false" /&gt;
&lt;/DockablePane&gt;
&lt;/ResizingPanel&gt;
&lt;DockablePane ResizeWidth="271" Anchor="Right"&gt;
&lt;DockableContent Name="content4" AutoHide="false" /&gt;
&lt;/DockablePane&gt;
&lt;/ResizingPanel&gt;
&lt;Hidden /&gt;
&lt;Windows /&gt;
&lt;/DockingManager&gt;</value>
</setting>
<setting name="AssemblyList" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>%ProgramFiles%\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll</string>
</ArrayOfString>
</value>
</setting>
<setting name="MainWindowState" serializeAs="String">
<value>Maximized</value>
</setting>
</ICSharpCode.XamlDesigner.Configuration.Settings>
</userSettings>
</configuration>

29
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Configuration/app.manifest

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>
</dependentAssembly>
</dependency>
</asmv1:assembly>

53
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Converters.cs

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;
using System.Windows;
using System.Collections;
namespace ICSharpCode.XamlDesigner.Converters
{
public class EnumToIntConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (int)value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
public class CollapsedWhenFalse : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class FalseWhenZero : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || (int)value == 0) {
return false;
}
return true;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

212
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Document.cs

@ -0,0 +1,212 @@ @@ -0,0 +1,212 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.IO;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.Xaml;
using System.Xml;
using ICSharpCode.WpfDesign;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Diagnostics;
namespace ICSharpCode.XamlDesigner
{
public class Document : INotifyPropertyChanged
{
public Document(string tempName, string text)
{
this.tempName = tempName;
Text = text;
IsDirty = false;
}
public Document(string filePath)
{
this.filePath = filePath;
ReloadFile();
}
string tempName;
DesignSurface designSurface = new DesignSurface();
string text;
public string Text {
get {
return text;
}
set {
if (text != value) {
text = value;
IsDirty = true;
RaisePropertyChanged("Text");
}
}
}
DocumentMode mode;
void SetMode(DocumentMode newMode)
{
mode = newMode;
if (IsDesign) {
UpdateDesign();
}
else {
UpdateXaml();
}
RaisePropertyChanged("IsXaml");
RaisePropertyChanged("IsDesign");
RaisePropertyChanged("SelectionService");
}
public bool IsXaml {
get { return mode == DocumentMode.Xaml; }
set { if (value) SetMode(DocumentMode.Xaml); }
}
public bool IsDesign {
get { return mode == DocumentMode.Design; }
set { if (value) SetMode(DocumentMode.Design); }
}
string filePath;
public string FilePath {
get {
return filePath;
}
private set {
filePath = value;
RaisePropertyChanged("FilePath");
RaisePropertyChanged("FileName");
RaisePropertyChanged("Title");
RaisePropertyChanged("Name");
}
}
bool isDirty;
public bool IsDirty {
get {
return isDirty;
}
private set {
isDirty = value;
RaisePropertyChanged("IsDirty");
RaisePropertyChanged("Name");
RaisePropertyChanged("Title");
}
}
public string FileName {
get {
if (FilePath == null) return null;
return Path.GetFileName(FilePath);
}
}
public string Name {
get {
return FileName ?? tempName;
}
}
public string Title {
get {
return IsDirty ? Name + "*" : Name;
}
}
public DesignSurface DesignSurface {
get { return designSurface; }
}
public DesignContext DesignContext {
get { return designSurface.DesignContext; }
}
public UndoService UndoService {
get { return DesignContext.Services.GetService<UndoService>(); }
}
public ISelectionService SelectionService {
get {
if (IsDesign && DesignContext != null) {
return DesignContext.Services.Selection;
}
return null;
}
}
void ReloadFile()
{
Text = File.ReadAllText(FilePath);
UpdateDesign();
IsDirty = false;
}
public void Save()
{
if (IsDesign) {
UpdateXaml();
}
File.WriteAllText(FilePath, Text);
IsDirty = false;
}
public void SaveAs(string filePath)
{
FilePath = filePath;
Save();
}
void UpdateXaml()
{
var sb = new StringBuilder();
using (var xmlWriter = XmlWriter.Create(sb)) {
try {
DesignSurface.SaveDesigner(xmlWriter);
Text = XamlFormatter.Format(sb.ToString());
}
catch (Exception x) {
Shell.ReportException(x);
}
}
}
void UpdateDesign()
{
try {
XamlLoadSettings settings = new XamlLoadSettings();
using (var xmlReader = XmlReader.Create(new StringReader(Text))) {
DesignSurface.LoadDesigner(xmlReader, settings);
}
UndoService.UndoStackChanged += delegate { IsDirty = true; };
}
catch (Exception x) {
Shell.ReportException(x);
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged(string name)
{
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion
enum DocumentMode
{
Xaml, Design
}
}
}

40
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/DocumentView.xaml

@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
<UserControl
x:Class="ICSharpCode.XamlDesigner.DocumentView"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Integration="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:TextEditor="clr-namespace:ICSharpCode.TextEditor;assembly=ICSharpCode.TextEditor"
>
<!--<TabControl TabStripPlacement="Bottom">
<TabItem Header="Xaml"
IsSelected="{Binding IsXaml}">
<Integration:WindowsFormsHost>
<TextEditor:TextEditorControl x:Name="uxTextEditor" />
</Integration:WindowsFormsHost>
</TabItem>
<TabItem Header="Design"
IsSelected="{Binding IsDesign}"
Content="{Binding DesignSurface}" />
</TabControl>-->
<DockPanel>
<StackPanel Orientation="Horizontal"
DockPanel.Dock="Bottom">
<ToggleButton IsChecked="{Binding IsXaml}"
Content="Xaml"
Style="{StaticResource TabButtonStyle}"/>
<ToggleButton IsChecked="{Binding IsDesign}"
Content="Design"
Style="{StaticResource TabButtonStyle}" />
</StackPanel>
<Grid>
<Integration:WindowsFormsHost Visibility="{Binding IsXaml, Converter={StaticResource CollapsedWhenFalse}}">
<TextEditor:TextEditorControl x:Name="uxTextEditor" />
</Integration:WindowsFormsHost>
<ContentPresenter Content="{Binding DesignSurface}"
Visibility="{Binding IsDesign, Converter={StaticResource CollapsedWhenFalse}}"/>
</Grid>
</DockPanel>
</UserControl>

26
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/DocumentView.xaml.cs

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ICSharpCode.XamlDesigner
{
public partial class DocumentView
{
public DocumentView(Document doc)
{
InitializeComponent();
uxTextEditor.SetHighlighting("XML");
uxTextEditor.DataBindings.Add("Text", doc, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
}
}
}

57
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/DragListener.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
namespace ICSharpCode.XamlDesigner
{
class DragListener
{
public DragListener(IInputElement target)
{
this.target = target;
target.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(target_PreviewMouseLeftButtonDown);
target.PreviewMouseMove += new MouseEventHandler(target_PreviewMouseMove);
}
public event MouseEventHandler DragStarted;
IInputElement target;
Window window;
Point startPoint;
bool readyToRaise;
Point GetMousePosition()
{
if (window == null) {
window = Window.GetWindow(target as DependencyObject);
}
return Mouse.GetPosition(window);
}
bool IsMovementBigEnough()
{
Point currentPoint = GetMousePosition();
return (Math.Abs(currentPoint.X - startPoint.X) >= SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(currentPoint.Y - startPoint.Y) >= SystemParameters.MinimumVerticalDragDistance);
}
void target_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
readyToRaise = true;
startPoint = GetMousePosition();
}
void target_PreviewMouseMove(object sender, MouseEventArgs e)
{
if (readyToRaise && IsMovementBigEnough()) {
readyToRaise = false;
if (DragStarted != null) {
DragStarted(target, e);
}
}
}
}
}

93
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/ExtensionMethods.cs

@ -0,0 +1,93 @@ @@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using System.IO;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Collections;
namespace ICSharpCode.XamlDesigner
{
static class ExtensionMethods
{
public static IEnumerable<string> Paths(this IDataObject data)
{
string[] paths = (string[])data.GetData(DataFormats.FileDrop);
if (paths != null) {
foreach (var path in paths) {
yield return path;
}
}
}
public static T GetObject<T>(this IDataObject data)
{
return (T)data.GetData(typeof(T).FullName);
}
public static T FindAncestor<T>(this DependencyObject d) where T : class
{
while (true) {
if (d == null) return null;
if (d is T) return d as T;
d = VisualTreeHelper.GetParent(d);
}
}
public static Stream ToStream(this string s)
{
return new MemoryStream(Encoding.UTF8.GetBytes(s));
}
public static void AddRange<T>(this ObservableCollection<T> col, IEnumerable<T> items)
{
foreach (var item in items) {
col.Add(item);
}
}
public static void KeepSyncronizedWith<S>(this IList target, ObservableCollection<S> source, Func<S, object> convert)
{
target.Clear();
foreach (var item in source) {
target.Add(convert(item));
}
source.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) {
switch (e.Action) {
case NotifyCollectionChangedAction.Add:
target.Add(convert((S)e.NewItems[0]));
break;
case NotifyCollectionChangedAction.Remove:
target.RemoveAt(e.OldStartingIndex);
break;
case NotifyCollectionChangedAction.Move:
target.RemoveAt(e.OldStartingIndex);
target.Insert(e.NewStartingIndex, e.NewItems[0]);
break;
case NotifyCollectionChangedAction.Replace:
target[e.NewStartingIndex] = convert((S)e.NewItems[0]);
break;
case NotifyCollectionChangedAction.Reset:
target.Clear();
break;
}
};
}
public static object GetDataContext(this RoutedEventArgs e)
{
var f = e.OriginalSource as FrameworkElement;
if (f != null) return f.DataContext;
return null;
}
}
}

BIN
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Images/Reference.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Images/Tag.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 389 B

BIN
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Libraries/AvalonDock.dll

Binary file not shown.

BIN
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Libraries/ICSharpCode.TextEditor.dll

Binary file not shown.

118
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/MainWindow.xaml

@ -0,0 +1,118 @@ @@ -0,0 +1,118 @@
<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"
xmlns:sd="http://sharpdevelop.net"
xmlns:AvalonDock="clr-namespace:AvalonDock;assembly=AvalonDock"
xmlns:XamlDesigner="clr-namespace:ICSharpCode.XamlDesigner"
SnapsToDevicePixels="True"
AllowDrop="True"
Title="{Binding Title}">
<Window.CommandBindings>
<CommandBinding Command="New"
Executed="NewCommand_Executed" />
<CommandBinding Command="Open"
Executed="OpenCommand_Executed" />
<CommandBinding Command="Close"
Executed="CloseCommand_Executed"
CanExecute="CurrentDocument_CanExecute"
PreviewExecuted="CloseCommand_PreviewExecuted"/>
<CommandBinding Command="XamlDesigner:MainWindow.CloseAllCommand"
Executed="CloseAllCommand_Executed"
CanExecute="CurrentDocument_CanExecute" />
<CommandBinding Command="Save"
Executed="SaveCommand_Executed"
CanExecute="CurrentDocument_CanExecute" />
<CommandBinding Command="SaveAs"
Executed="SaveAsCommand_Executed"
CanExecute="CurrentDocument_CanExecute" />
<CommandBinding Command="XamlDesigner:MainWindow.SaveAllCommand"
Executed="SaveAllCommand_Executed"
CanExecute="CurrentDocument_CanExecute" />
<CommandBinding Command="XamlDesigner:MainWindow.ExitCommand"
Executed="ExitCommand_Executed" />
</Window.CommandBindings>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="File">
<MenuItem Command="New" />
<MenuItem Command="Open" />
<Separator />
<MenuItem Command="Close" />
<MenuItem Command="XamlDesigner:MainWindow.CloseAllCommand" />
<Separator />
<MenuItem Command="Save" />
<MenuItem Command="SaveAs" />
<MenuItem Command="XamlDesigner:MainWindow.SaveAllCommand" />
<Separator />
<MenuItem Header="Recent Files"
ItemsSource="{Binding RecentFiles}"
IsEnabled="{Binding RecentFiles.Count, Converter={StaticResource FalseWhenZero}}"
Click="RecentFiles_Click"/>
<Separator />
<MenuItem Command="XamlDesigner:MainWindow.ExitCommand" />
</MenuItem>
<MenuItem Header="Edit">
<MenuItem Command="Undo" />
<MenuItem Command="Redo" />
<Separator />
<MenuItem Command="Cut" />
<MenuItem Command="Copy" />
<MenuItem Command="Paste" />
<MenuItem Command="Delete" />
<MenuItem Command="SelectAll" />
<Separator />
<MenuItem Command="Find" />
</MenuItem>
</Menu>
<AvalonDock:DockingManager x:Name="uxDockingManager">
<AvalonDock:ResizingPanel>
<AvalonDock:DocumentPane x:Name="uxDocumentPane"
SelectedValue="{Binding CurrentDocument}"
SelectedValuePath="DataContext"/>
<AvalonDock:DockablePane>
<AvalonDock:DockableContent x:Name="content1" Title="Toolbox">
<XamlDesigner:ToolboxView />
</AvalonDock:DockableContent>
</AvalonDock:DockablePane>
<AvalonDock:DockablePane>
<AvalonDock:DockableContent x:Name="content2" Title="Outline">
<!--<XamlDesigner:SceneTreeView />-->
</AvalonDock:DockableContent>
</AvalonDock:DockablePane>
<AvalonDock:DockablePane>
<AvalonDock:DockableContent x:Name="content3" Title="Errors">
<!--<XamlDesigner:ErrorListView />-->
</AvalonDock:DockableContent>
</AvalonDock:DockablePane>
<AvalonDock:DockablePane>
<AvalonDock:DockableContent x:Name="content4" Title="Properties">
<sd:PropertyGridView x:Name="uxPropertyGridView"
SelectedItems="{Binding DataContext.CurrentDocument.SelectionService.SelectedItems, ElementName=root, FallbackValue={x:Null}}"/>
</AvalonDock:DockableContent>
</AvalonDock:DockablePane>
</AvalonDock:ResizingPanel>
</AvalonDock:DockingManager>
</DockPanel>
</Window>

181
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/MainWindow.xaml.cs

@ -0,0 +1,181 @@ @@ -0,0 +1,181 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ICSharpCode.XamlDesigner.Configuration;
using System.ComponentModel;
using Microsoft.Win32;
using AvalonDock;
using System.IO;
using System.Collections.Specialized;
namespace ICSharpCode.XamlDesigner
{
public partial class MainWindow
{
public MainWindow()
{
RenameCommands();
Instance = this;
DataContext = Shell.Instance;
InitializeComponent();
Shell.Instance.PropertyGrid = uxPropertyGridView.PropertyGrid;
AvalonDockWorkaround();
LoadSettings();
ProcessPaths(App.Args);
}
public static MainWindow Instance;
OpenFileDialog openFileDialog;
SaveFileDialog saveFileDialog;
protected override void OnDragEnter(DragEventArgs e)
{
ProcessDrag(e);
}
protected override void OnDragOver(DragEventArgs e)
{
ProcessDrag(e);
}
protected override void OnDrop(DragEventArgs e)
{
ProcessPaths(e.Data.Paths());
}
protected override void OnClosing(CancelEventArgs e)
{
if (Shell.Instance.PrepareExit()) {
SaveSettings();
}
else {
e.Cancel = true;
}
base.OnClosing(e);
}
void RecentFiles_Click(object sender, RoutedEventArgs e)
{
var path = (string)(e.OriginalSource as MenuItem).Header;
Shell.Instance.Open(path);
}
void ProcessDrag(DragEventArgs e)
{
e.Effects = DragDropEffects.None;
e.Handled = true;
foreach (var path in e.Data.Paths()) {
if (path.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) ||
path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) {
e.Effects = DragDropEffects.Copy;
break;
}
else if (path.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase)) {
e.Effects = DragDropEffects.Copy;
break;
}
}
}
void ProcessPaths(IEnumerable<string> paths)
{
foreach (var path in paths) {
if (path.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase) ||
path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) {
Toolbox.Instance.AddAssembly(path);
}
else if (path.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase)) {
Shell.Instance.Open(path);
}
}
}
public string AskOpenFileName()
{
if (openFileDialog == null) {
openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Xaml Documents (*.xaml)|*.xaml";
}
if ((bool)openFileDialog.ShowDialog()) {
return openFileDialog.FileName;
}
return null;
}
public string AskSaveFileName(string initName)
{
if (saveFileDialog == null) {
saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Xaml Documents (*.xaml)|*.xaml";
}
saveFileDialog.FileName = initName;
if ((bool)saveFileDialog.ShowDialog()) {
return saveFileDialog.FileName;
}
return null;
}
void LoadSettings()
{
WindowState = Settings.Default.MainWindowState;
Rect r = Settings.Default.MainWindowRect;
if (r != new Rect()) {
Left = r.Left;
Top = r.Top;
Width = r.Width;
Height = r.Height;
}
if (Settings.Default.AvalonDockLayout != null) {
uxDockingManager.RestoreLayout(Settings.Default.AvalonDockLayout.ToStream());
}
}
void SaveSettings()
{
Settings.Default.MainWindowState = WindowState;
if (WindowState == WindowState.Normal) {
Settings.Default.MainWindowRect = new Rect(Left, Top, Width, Height);
}
var writer = new StringWriter();
uxDockingManager.SaveLayout(writer);
Settings.Default.AvalonDockLayout = writer.ToString();
Shell.Instance.SaveSettings();
}
#region AvalonDockWorkaround
void AvalonDockWorkaround()
{
uxDocumentPane.Items.KeepSyncronizedWith(Shell.Instance.Documents, d => CreateContentFor(d));
}
DocumentContent CreateContentFor(Document doc)
{
var content = new DocumentContent() {
DataContext = doc,
Content = new DocumentView(doc)
};
content.SetBinding(DocumentContent.TitleProperty, "Title");
return content;
}
#endregion
}
}

71
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/MainWindow_Commands.cs

@ -0,0 +1,71 @@ @@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
namespace ICSharpCode.XamlDesigner
{
public partial class MainWindow
{
public static SimpleCommand CloseAllCommand = new SimpleCommand("Close All");
public static SimpleCommand SaveAllCommand = new SimpleCommand("Save All", ModifierKeys.Control | ModifierKeys.Shift, Key.S);
public static SimpleCommand ExitCommand = new SimpleCommand("Exit");
static void RenameCommands()
{
ApplicationCommands.Open.Text = "Open...";
ApplicationCommands.SaveAs.Text = "Save As...";
}
void NewCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
Shell.Instance.New();
}
void OpenCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
Shell.Instance.Open();
}
void CloseCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
Shell.Instance.CloseCurrentDocument();
}
void CloseCommand_PreviewExecuted(object sender, ExecutedRoutedEventArgs e)
{
Shell.Instance.CloseCurrentDocument();
}
void CloseAllCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
Shell.Instance.CloseAll();
}
void SaveCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
Shell.Instance.SaveCurrentDocument();
}
void SaveAsCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
Shell.Instance.SaveCurrentDocumentAs();
}
void SaveAllCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
Shell.Instance.SaveAll();
}
void ExitCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
Shell.Instance.Exit();
}
void CurrentDocument_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = Shell.Instance.CurrentDocument != null;
}
}
}

4
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/NewFileTemplate.xaml

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
<Window xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</Window>

107
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Outline.xaml

@ -0,0 +1,107 @@ @@ -0,0 +1,107 @@
<UserControl x:Class="ICSharpCode.XamlDesigner.Outline"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:XamlDesigner="clr-namespace:ICSharpCode.XamlDesigner;assembly="
DataContext="{Binding CurrentDocument}">
<UserControl.Resources>
<Style TargetType="{x:Type XamlDesigner:OutlineTree}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type XamlDesigner:OutlineTree}">
<Grid>
<ScrollViewer>
<ItemsPresenter />
</ScrollViewer>
<Border x:Name="PART_InsertLine"
Background="#FFC73C"
Height="2"
VerticalAlignment="Top"
Visibility="Collapsed"
IsHitTestVisible="False" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type XamlDesigner:OutlineTreeItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type XamlDesigner:OutlineTreeItem}">
<DockPanel Background="Transparent">
<Grid DockPanel.Dock="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border x:Name="Bg"
Background="{TemplateBinding Background}"
Grid.ColumnSpan="2"
Margin="0 1 0 0" />
<ToggleButton x:Name="Expander"
Width="19"
Margin="{TemplateBinding Indent}"
Style="{StaticResource ExpandCollapseToggleStyle}"
ClickMode="Press"
IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" />
<ContentPresenter x:Name="PART_Header"
ContentSource="Header"
Grid.Column="1" />
</Grid>
<ItemsPresenter x:Name="ItemsHost" />
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsExpanded"
Value="false">
<Setter TargetName="ItemsHost"
Property="Visibility"
Value="Collapsed" />
</Trigger>
<Trigger Property="HasItems"
Value="false">
<Setter TargetName="Expander"
Property="Visibility"
Value="Hidden" />
</Trigger>
<Trigger Property="IsSelected"
Value="true">
<Setter TargetName="Bg"
Property="Background"
Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type XamlDesigner:TreeNode}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type XamlDesigner:TreeNode}">
<StackPanel Orientation="Horizontal">
<Image Source="{TemplateBinding Image}"
Stretch="None" />
<ContentPresenter VerticalAlignment="Center"
Margin="5 0 0 0" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<HierarchicalDataTemplate DataType="{x:Type XamlDesigner:DocumentElement}"
ItemsSource="{Binding Children}">
<XamlDesigner:TreeNode Image="Images/Tag.png"
Content="{Binding XamlType.Name}" />
</HierarchicalDataTemplate>
</UserControl.Resources>
<XamlDesigner:OutlineTree ItemsSource="{Binding EnumerateRoot}"
Selection="{Binding Selection, Mode=OneWay}" />
</UserControl>

24
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Outline.xaml.cs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ICSharpCode.XamlDesigner
{
public partial class Outline
{
public Outline()
{
InitializeComponent();
}
}
}

267
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/OutlineTree.cs

@ -0,0 +1,267 @@ @@ -0,0 +1,267 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Controls.Primitives;
namespace ICSharpCode.XamlDesigner
{
public class OutlineTree : TreeView
{
public OutlineTree()
{
AllowDrop = true;
new DragListener(this).DragStarted += new MouseEventHandler(TreeList_DragStarted);
DragEnter += new DragEventHandler(TreeList_DragEnter);
DragOver += new DragEventHandler(TreeList_DragOver);
Drop += new DragEventHandler(TreeList_Drop);
//Selection = new ObservableCollection<object>();
}
Border insertLine;
OutlineTreeItem markedItem;
OutlineTreeItem possibleSelection;
List<OutlineTreeItem> selectionNodes = new List<OutlineTreeItem>();
public static readonly DependencyProperty SelectionProperty =
DependencyProperty.Register("Selection", typeof(ObservableCollection<DocumentElement>), typeof(OutlineTree));
public ObservableCollection<DocumentElement> Selection {
get { return (ObservableCollection<DocumentElement>)GetValue(SelectionProperty); }
set { SetValue(SelectionProperty, value); }
}
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
insertLine = (Border)Template.FindName("PART_InsertLine", this);
}
protected override DependencyObject GetContainerForItemOverride()
{
return new OutlineTreeItem();
}
protected override bool IsItemItsOwnContainerOverride(object item)
{
return item is OutlineTreeItem;
}
protected virtual DragDropEffects CanDrag(object obj)
{
return DragDropEffects.Move;
}
protected virtual DragDropEffects CanDrop(object obj, object parent, int index)
{
return DragDropEffects.Move;
}
void TreeList_DragOver(object sender, DragEventArgs e)
{
ProcessDrag(e);
}
void TreeList_DragEnter(object sender, DragEventArgs e)
{
ProcessDrag(e);
}
void TreeList_Drop(object sender, DragEventArgs e)
{
ProcessDrop(e);
}
protected override void OnDragLeave(DragEventArgs e)
{
HideDropMarkers();
}
void TreeList_DragStarted(object sender, MouseEventArgs e)
{
possibleSelection = null;
object obj = (e.OriginalSource as FrameworkElement).DataContext;
if (obj != null) {
DragDropEffects effects = CanDrag(obj);
if (effects != DragDropEffects.None) {
DragDrop.DoDragDrop(this, obj, effects);
}
}
}
void ProcessDrag(DragEventArgs e)
{
e.Effects = DragDropEffects.Move;
e.Handled = true;
OutlineTreeItem treeItem = (e.OriginalSource as DependencyObject).FindAncestor<OutlineTreeItem>();
if (treeItem != null) {
HideDropMarkers();
ContentPresenter header = treeItem.HeaderPresenter;
Point p = e.GetPosition(header);
int part = (int)(p.Y / (header.ActualHeight / 3));
if (part == 1) {
markedItem = treeItem;
markedItem.Background = insertLine.Background;
}
else {
insertLine.Visibility = Visibility.Visible;
p = header.TransformToVisual(this).Transform(new Point());
double y = part == 0 ? p.Y : p.Y + header.ActualHeight;
insertLine.Margin = new Thickness(0, y, 0, 0);
}
}
}
void ProcessDrop(DragEventArgs e)
{
HideDropMarkers();
}
void HideDropMarkers()
{
insertLine.Visibility = Visibility.Collapsed;
if (markedItem != null) {
markedItem.ClearValue(OutlineTreeItem.BackgroundProperty);
}
}
void Select(OutlineTreeItem item)
{
item.IsSelected = true;
Selection.Add(item.Element);
selectionNodes.Add(item);
}
void SelectOnly(OutlineTreeItem item)
{
foreach (var node in selectionNodes) {
node.IsSelected = false;
}
Selection.Clear();
Select(item);
}
void Unselect(OutlineTreeItem item)
{
item.IsSelected = false;
Selection.Remove(item.Element);
selectionNodes.Remove(item);
}
internal void HandleItemMouseDown(OutlineTreeItem item)
{
bool control = Keyboard.IsKeyDown(Key.LeftCtrl);
if (item.IsSelected) {
if (control) {
Unselect(item);
}
else {
possibleSelection = item;
}
}
else {
if (control) {
Select(item);
}
else {
SelectOnly(item);
}
}
}
internal void HandleItemMouseUp(OutlineTreeItem item)
{
if (possibleSelection != null) {
SelectOnly(possibleSelection);
}
}
}
public class OutlineTreeItem : TreeViewItem
{
public new static readonly DependencyProperty IsSelectedProperty =
Selector.IsSelectedProperty.AddOwner(typeof(OutlineTreeItem));
public new bool IsSelected {
get { return (bool)GetValue(IsSelectedProperty); }
set { SetValue(IsSelectedProperty, value); }
}
public ContentPresenter HeaderPresenter {
get { return (ContentPresenter)Template.FindName("PART_Header", this); }
}
public DocumentElement Element {
get { return DataContext as DocumentElement; }
}
public static readonly DependencyProperty IndentProperty =
DependencyProperty.Register("Indent", typeof(Thickness), typeof(OutlineTreeItem));
public Thickness Indent {
get { return (Thickness)GetValue(IndentProperty); }
set { SetValue(IndentProperty, value); }
}
protected override void OnVisualParentChanged(DependencyObject oldParent)
{
base.OnVisualParentChanged(oldParent);
OutlineTreeItem parent = ItemsControl.ItemsControlFromItemContainer(this) as OutlineTreeItem;
Indent = parent == null ? new Thickness() : new Thickness(parent.Indent.Left + 19, 0, 0, 0);
}
protected override DependencyObject GetContainerForItemOverride()
{
return new OutlineTreeItem();
}
protected override bool IsItemItsOwnContainerOverride(object item)
{
return item is OutlineTreeItem;
}
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
if (e.Source is ToggleButton || e.Source is ItemsPresenter) return;
OutlineTree tree = this.FindAncestor<OutlineTree>();
if (tree != null) {
tree.HandleItemMouseDown(this);
e.Handled = true;
}
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
OutlineTree tree = this.FindAncestor<OutlineTree>();
if (tree != null) {
tree.HandleItemMouseUp(this);
}
}
}
public class TreeNode : ContentControl
{
public static readonly DependencyProperty ImageProperty =
DependencyProperty.Register("Image", typeof(ImageSource), typeof(TreeNode));
public ImageSource Image {
get { return (ImageSource)GetValue(ImageProperty); }
set { SetValue(ImageProperty, value); }
}
}
}

238
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Shell.cs

@ -0,0 +1,238 @@ @@ -0,0 +1,238 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
using ICSharpCode.WpfDesign.Designer.PropertyGrid;
using ICSharpCode.XamlDesigner.Configuration;
using System.Collections.Specialized;
using System.IO;
using System.Windows;
using System.Diagnostics;
namespace ICSharpCode.XamlDesigner
{
public class Shell : INotifyPropertyChanged
{
public Shell()
{
Documents = new ObservableCollection<Document>();
RecentFiles = new ObservableCollection<string>();
LoadSettings();
}
public static Shell Instance = new Shell();
public const string ApplicationTitle = "Xaml Designer";
//public Toolbox Toolbox { get; set; }
//public SceneTree SceneTree { get; set; }
public PropertyGrid PropertyGrid { get; internal set; }
//public ErrorList ErrorList { get; set; }
public ObservableCollection<Document> Documents { get; private set; }
public ObservableCollection<string> RecentFiles { get; private set; }
Document currentDocument;
public Document CurrentDocument {
get {
return currentDocument;
}
set {
currentDocument = value;
RaisePropertyChanged("CurrentDocument");
RaisePropertyChanged("Title");
}
}
public string Title {
get {
if (CurrentDocument != null) {
return CurrentDocument.Title + " - " + ApplicationTitle;
}
return ApplicationTitle;
}
}
void LoadSettings()
{
if (Settings.Default.RecentFiles != null) {
RecentFiles.AddRange(Settings.Default.RecentFiles.Cast<string>());
}
}
public void SaveSettings()
{
if (Settings.Default.RecentFiles == null) {
Settings.Default.RecentFiles = new StringCollection();
}
else {
Settings.Default.RecentFiles.Clear();
}
foreach (var f in RecentFiles) {
Settings.Default.RecentFiles.Add(f);
}
}
public static void ReportException(Exception x)
{
MessageBox.Show(x.ToString());
}
#region Files
bool IsSomethingDirty {
get {
foreach (var doc in Shell.Instance.Documents) {
if (doc.IsDirty) return true;
}
return false;
}
}
static int nonameIndex = 1;
public void New()
{
Document doc = new Document("New" + nonameIndex++, File.ReadAllText("NewFileTemplate.xaml"));
Documents.Add(doc);
CurrentDocument = doc;
}
public void Open()
{
var path = MainWindow.Instance.AskOpenFileName();
if (path != null) {
Open(path);
}
}
public void Open(string path)
{
path = Path.GetFullPath(path);
if (RecentFiles.Contains(path)) {
RecentFiles.Remove(path);
}
RecentFiles.Insert(0, path);
foreach (var doc in Documents) {
if (doc.FilePath == path) {
CurrentDocument = doc;
return;
}
}
var newDoc = new Document(path);
Documents.Add(newDoc);
CurrentDocument = newDoc;
}
public bool Save(Document doc)
{
if (doc.IsDirty) {
if (doc.FilePath == null) {
return SaveAs(doc);
}
doc.Save();
}
return true;
}
public bool SaveAs(Document doc)
{
var initName = doc.FileName ?? doc.Name + ".xaml";
var path = MainWindow.Instance.AskSaveFileName(initName);
if (path != null) {
doc.SaveAs(path);
return true;
}
return false;
}
public bool SaveAll()
{
foreach (var doc in Documents) {
if (!Save(doc)) return false;
}
return true;
}
public bool Close(Document doc)
{
if (doc.IsDirty) {
var result = MessageBox.Show("Save \"" + doc.Name + "\" ?", Shell.ApplicationTitle,
MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes) {
if (!Save(doc)) return false;
}
else if (result == MessageBoxResult.Cancel) {
return false;
}
}
Documents.Remove(doc);
return true;
}
public bool CloseAll()
{
foreach (var doc in Documents) {
if (!Close(doc)) return false;
}
return true;
}
public bool PrepareExit()
{
if (IsSomethingDirty) {
var result = MessageBox.Show("Save All?", Shell.ApplicationTitle,
MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes) {
if (!SaveAll()) return false;
}
else if (result == MessageBoxResult.Cancel) {
return false;
}
}
return true;
}
public void Exit()
{
MainWindow.Instance.Close();
}
public void SaveCurrentDocument()
{
Save(CurrentDocument);
}
public void SaveCurrentDocumentAs()
{
SaveAs(CurrentDocument);
}
public void CloseCurrentDocument()
{
Close(CurrentDocument);
}
#endregion
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged(string name)
{
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion
}
}

27
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/SimpleCommand.cs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
namespace ICSharpCode.XamlDesigner
{
public class SimpleCommand : RoutedUICommand
{
public SimpleCommand(string text)
{
Text = text;
}
public SimpleCommand(string text, ModifierKeys modifiers, Key key)
{
InputGestures.Add(new KeyGesture(key, modifiers));
Text = text;
}
public SimpleCommand(string text, Key key)
: this(text, ModifierKeys.None, key)
{
}
}
}

31
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/TestFiles/1.xaml

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
<Window xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WindowTitle"
BorderThickness="10"
Width="400"
Height="300">
<StackPanel>
<Canvas Height="50">
<Button>CB</Button>
</Canvas>
<TabControl MinHeight="150">
<TabItem Header="StackPanel">
<StackPanel>
<Button>a</Button>
</StackPanel>
</TabItem>
<TabItem Header="Button">
<Button>button on page 2</Button>
</TabItem>
<TabItem Header="Canvas">
<Canvas />
</TabItem>
<TabItem Header="Grid">
<Grid />
</TabItem>
<TabItem Header="DockPanel">
<DockPanel />
</TabItem>
</TabControl>
</StackPanel>
</Window>

41
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/TestFiles/2.xaml

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
<Window xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas>
<Button Content="bla-bla"
Width="110"
Height="76"
Canvas.Left="59"
Canvas.Top="158" />
<Ellipse Width="146"
Height="63"
Fill="#FF5DAF05"
Canvas.Left="50"
Canvas.Top="285" />
<Grid Width="279"
Height="233"
Background="#FFFFFFE1"
Canvas.Left="255"
Canvas.Top="167">
<Panel.Children>
<TextBlock Width="59"
Height="39"
Margin="0,10,12,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
FontSize="33"
Text="Grid"
Grid.Column="0"
Grid.Row="0" />
</Panel.Children>
</Grid>
<StackPanel Width="345"
Height="73"
Background="#FFEDEDED"
Canvas.Left="198"
Canvas.Top="51" />
<TextBlock FontSize="14"
Text="StackPanel"
Canvas.Left="323"
Canvas.Top="28" />
</Canvas>
</Window>

101
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/Toolbox.cs

@ -0,0 +1,101 @@ @@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Collections.ObjectModel;
using ICSharpCode.XamlDesigner.Configuration;
using System.Windows;
using System.Collections.Specialized;
namespace ICSharpCode.XamlDesigner
{
public class Toolbox
{
public Toolbox()
{
AssemblyNodes = new ObservableCollection<AssemblyNode>();
LoadSettings();
}
public static Toolbox Instance = new Toolbox();
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)) {
node.Controls.Add(new ControlNode() { Type = t });
}
}
node.Controls.Sort(delegate(ControlNode c1, ControlNode c2) {
return c1.Name.CompareTo(c2.Name);
});
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)
{
AssemblyNodes.Remove(node);
Settings.Default.AssemblyList.Remove(node.Path);
}
public void LoadSettings()
{
if (Settings.Default.AssemblyList != null) {
foreach (var path in Settings.Default.AssemblyList) {
AddAssembly(Environment.ExpandEnvironmentVariables(path), false);
}
}
}
static bool IsControl(Type t)
{
return !t.IsAbstract && !t.IsGenericTypeDefinition && t.IsSubclassOf(typeof(FrameworkElement));
}
}
public class AssemblyNode
{
public AssemblyNode()
{
Controls = new List<ControlNode>();
}
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 class ControlNode
{
public Type Type { get; set; }
public string Name {
get { return Type.Name; }
}
}
}

43
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/ToolboxView.xaml

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
<UserControl x:Class="ICSharpCode.XamlDesigner.ToolboxView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:XamlDesigner="clr-namespace:ICSharpCode.XamlDesigner;assembly=">
<UserControl.Resources>
<HierarchicalDataTemplate DataType="{x:Type XamlDesigner:AssemblyNode}"
ItemsSource="{Binding Controls}">
<StackPanel Orientation="Horizontal"
ToolTip="{Binding Path}">
<Border Background="White"
Margin="-1 0 0 0"
>
<Image Source="Images/Reference.png"
Height="16"/>
</Border>
<TextBlock Text="{Binding Name}"
Margin="5 0"
VerticalAlignment="Center"/>
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type XamlDesigner:ControlNode}">
<StackPanel Orientation="Horizontal"
ToolTip="{Binding Type.FullName}">
<Border Background="White"
Margin="-1 0 0 0">
<Image Source="Images/Tag.png" />
</Border>
<TextBlock Text="{Binding Type.Name}"
Margin="5 0"
VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<TreeView x:Name="uxTreeView"
ItemsSource="{Binding AssemblyNodes}"
BorderThickness="0"
SelectedItemChanged="uxTreeView_SelectedItemChanged"/>
</UserControl>

69
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/ToolboxView.xaml.cs

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.XamlDesigner
{
public partial class ToolboxView
{
public ToolboxView()
{
DataContext = Toolbox.Instance;
InitializeComponent();
new DragListener(this).DragStarted += new MouseEventHandler(Toolbox_DragStarted);
}
void Toolbox_DragStarted(object sender, MouseEventArgs e)
{
PrepareTool(e.GetDataContext() as ControlNode, true);
}
void uxTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
PrepareTool(uxTreeView.SelectedItem as ControlNode, false);
}
void PrepareTool(ControlNode node, bool drag)
{
if (node != null) {
var tool = new CreateComponentTool(node.Type);
if (Shell.Instance.CurrentDocument != null) {
Shell.Instance.CurrentDocument.DesignContext.Services.Tool.CurrentTool = tool;
if (drag) {
DragDrop.DoDragDrop(this, tool, DragDropEffects.Copy);
}
}
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Delete) {
Remove();
}
}
void Remove()
{
AssemblyNode node = uxTreeView.SelectedItem as AssemblyNode;
if (node != null) {
Toolbox.Instance.Remove(node);
}
}
}
}

168
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/XamlDesigner.csproj

@ -0,0 +1,168 @@ @@ -0,0 +1,168 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30428</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{27DA2B5C-2AAA-4478-AB00-3E184273C241}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ICSharpCode.XamlDesigner</RootNamespace>
<AssemblyName>XamlDesigner</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<ApplicationManifest>Configuration\app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AvalonDock, Version=1.1.1231.0, Culture=neutral, PublicKeyToken=85a1e0ada7ec13e4, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\AvalonDock.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.TextEditor, Version=3.0.0.3244, Culture=neutral, PublicKeyToken=4d61825e8dd49f1a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Libraries\ICSharpCode.TextEditor.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UIAutomationProvider">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsFormsIntegration">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Configuration\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
<Compile Include="Converters.cs" />
<Compile Include="Document.cs" />
<Compile Include="DocumentView.xaml.cs">
<DependentUpon>DocumentView.xaml</DependentUpon>
</Compile>
<Compile Include="DragListener.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="MainWindow_Commands.cs" />
<Compile Include="Shell.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
</Compile>
<Compile Include="SimpleCommand.cs" />
<Compile Include="Toolbox.cs" />
<Compile Include="ToolboxView.xaml.cs">
<DependentUpon>ToolboxView.xaml</DependentUpon>
</Compile>
<Compile Include="XamlFormatter.cs" />
</ItemGroup>
<ItemGroup>
<None Include="NewFileTemplate.xaml">
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Page Include="DocumentView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<None Include="TestFiles\1.xaml">
<SubType>Designer</SubType>
</None>
<None Include="TestFiles\2.xaml">
<SubType>Designer</SubType>
</None>
<Page Include="ToolboxView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<None Include="Configuration\app.config" />
<None Include="Configuration\app.manifest" />
<None Include="Configuration\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Reference.png" />
<Resource Include="Images\Tag.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WpfDesign.Designer\Project\WpfDesign.Designer.csproj">
<Project>{78CC29AC-CC79-4355-B1F2-97936DF198AC}</Project>
<Name>WpfDesign.Designer</Name>
</ProjectReference>
<ProjectReference Include="..\WpfDesign\Project\WpfDesign.csproj">
<Project>{66A378A1-E9F4-4AD5-8946-D0EC06C2902F}</Project>
<Name>WpfDesign</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

204
src/AddIns/DisplayBindings/WpfDesign/XamlDesigner/XamlFormatter.cs

@ -0,0 +1,204 @@ @@ -0,0 +1,204 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace ICSharpCode.XamlDesigner
{
public static class XamlFormatter
{
public static char IndentChar = ' ';
public static int Indenation = 2;
public static int LengthBeforeNewLine = 60;
static StringBuilder sb;
static int currentColumn;
static int nextColumn;
public static string Format(string xaml)
{
sb = new StringBuilder();
currentColumn = 0;
nextColumn = 0;
try {
var doc = XDocument.Parse(xaml);
WalkContainer(doc);
return sb.ToString();
}
catch {
return xaml;
}
}
static void WalkContainer(XContainer node)
{
foreach (var c in node.Nodes()) {
if (c is XElement) {
WalkElement(c as XElement);
}
else {
NewLine();
Append(c.ToString());
}
}
}
static void WalkElement(XElement e)
{
NewLine();
string prefix1 = e.GetPrefixOfNamespace(e.Name.Namespace);
string name1 = prefix1 == null ? e.Name.LocalName : prefix1 + ":" + e.Name.LocalName;
Append("<" + name1);
List<AttributeString> list = new List<AttributeString>();
int length = name1.Length;
foreach (var a in e.Attributes()) {
string prefix2 = e.GetPrefixOfNamespace(a.Name.Namespace);
var g = new AttributeString() { Name = a.Name, Prefix = prefix2, Value = a.Value };
list.Add(g);
length += g.FinalString.Length;
}
list.Sort(AttributeComparrer.Instance);
if (length > LengthBeforeNewLine) {
nextColumn = currentColumn + 1;
for (int i = 0; i < list.Count; i++) {
if (i > 0) {
NewLine();
}
else {
Append(" ");
}
Append(list[i].FinalString);
}
nextColumn -= name1.Length + 2;
}
else {
foreach (var a in list) {
Append(" " + a.FinalString);
}
}
if (e.Nodes().Count() > 0) {
Append(">");
nextColumn += Indenation;
WalkContainer(e);
nextColumn -= Indenation;
NewLine();
Append("</" + e.Name.LocalName + ">");
}
else {
Append(" />");
}
}
static void NewLine()
{
if (sb.Length > 0) {
sb.AppendLine();
sb.Append(new string(' ', nextColumn));
currentColumn = nextColumn;
}
}
static void Append(string s)
{
sb.Append(s);
currentColumn += s.Length;
}
enum AttributeLayout
{
X,
XmlnsMicrosoft,
Xmlns,
XmlnsWithClr,
SpecialOrder,
ByName,
Attached,
WithPrefix
}
class AttributeString
{
public XName Name;
public string Prefix;
public string Value;
public string LocalName {
get { return Name.LocalName; }
}
public string FinalName {
get {
return Prefix == null ? Name.LocalName : Prefix + ":" + Name.LocalName;
}
}
public string FinalString {
get {
return FinalName + "=\"" + Value + "\"";
}
}
public AttributeLayout GetAttributeLayout()
{
if (Prefix == "xmlns" || LocalName == "xmlns") {
if (Value.StartsWith("http://schemas.microsoft.com")) return AttributeLayout.XmlnsMicrosoft;
if (Value.StartsWith("clr")) return AttributeLayout.XmlnsWithClr;
return AttributeLayout.Xmlns;
}
if (Prefix == "x") return AttributeLayout.X;
if (Prefix != null) return AttributeLayout.WithPrefix;
if (LocalName.Contains(".")) return AttributeLayout.Attached;
if (AttributeComparrer.SpecialOrder.Contains(LocalName)) return AttributeLayout.SpecialOrder;
return AttributeLayout.ByName;
}
}
class AttributeComparrer : IComparer<AttributeString>
{
public static AttributeComparrer Instance = new AttributeComparrer();
public int Compare(AttributeString a1, AttributeString a2)
{
var y1 = a1.GetAttributeLayout();
var y2 = a2.GetAttributeLayout();
if (y1 == y2) {
if (y1 == AttributeLayout.SpecialOrder) {
return
Array.IndexOf(SpecialOrder, a1.LocalName).CompareTo(
Array.IndexOf(SpecialOrder, a2.LocalName));
}
return a1.FinalName.CompareTo(a2.FinalName);
}
return y1.CompareTo(y2);
}
public static string[] SpecialOrder = new string[] {
"Name",
"Content",
"Command",
"Executed",
"CanExecute",
"Width",
"Height",
"Margin",
"HorizontalAlignment",
"VerticalAlignment",
"HorizontalContentAlignment",
"VerticalContentAlignment",
"StartPoint",
"EndPoint",
"Offset",
"Color"
};
}
}
}
Loading…
Cancel
Save