Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions WpfDesign.Designer/Project/Controls/DragListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,43 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
{
public delegate void DragHandler(DragListener drag);

public class DragListener
public class DragListener : IDisposable
{
static DragListener()
{
InputManager.Current.PostProcessInput += new ProcessInputEventHandler(PostProcessInput);
}

public Transform Transform { get; set; }


private bool _disposed;

public DragListener(IInputElement target)
{
Target = target;

Target.PreviewMouseLeftButtonDown += Target_MouseDown;
Target.PreviewMouseMove += Target_MouseMove;
Target.PreviewMouseLeftButtonUp += Target_MouseUp;
}

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (!_disposed) {
if (disposing && Target != null) {
Target.PreviewMouseLeftButtonDown -= Target_MouseDown;
Target.PreviewMouseMove -= Target_MouseMove;
Target.PreviewMouseLeftButtonUp -= Target_MouseUp;
}
_disposed = true;
}
}

public void ExternalStart()
{
Expand Down
8 changes: 7 additions & 1 deletion WpfDesign.Designer/Project/OutlineView/OutlineNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace ICSharpCode.WpfDesign.Designer.OutlineView
{
public class OutlineNode: OutlineNodeBase
public class OutlineNode: OutlineNodeBase, IDisposable
{
protected OutlineNode(DesignItem designitem): base(designitem)
{
Expand All @@ -35,6 +35,12 @@ protected OutlineNode(string name) : base(name)
{
}

public virtual void Dispose()
{
SelectionService.SelectionChanged -= Selection_SelectionChanged;
DisposeEventHandlers();
}

static OutlineNode()
{
DummyPlacementType = PlacementType.Register("DummyPlacement");
Expand Down
37 changes: 27 additions & 10 deletions WpfDesign.Designer/Project/OutlineView/OutlineNodeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ protected OutlineNodeBase(DesignItem designItem)
{
hidden = object.Equals(designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsHiddenProperty).GetConvertedValueOnInstance<bool>(), true);
}
catch (Exception)
{ }
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Failed to get IsHiddenProperty: {ex.Message}");
}
if (hidden) {
_isDesignTimeVisible = false;
}
Expand All @@ -68,15 +70,15 @@ protected OutlineNodeBase(DesignItem designItem)
{
locked = object.Equals(designItem.Properties.GetAttachedProperty(DesignTimeProperties.IsLockedProperty).GetConvertedValueOnInstance<bool>(), true);
}
catch (Exception)
{ }
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Failed to get IsLockedProperty: {ex.Message}");
}
if (locked) {
_isDesignTimeLocked = true;
}

//TODO

DesignItem.NameChanged += new EventHandler(DesignItem_NameChanged);
DesignItem.NameChanged += new EventHandler(DesignItem_NameChanged);

if (DesignItem.ContentProperty != null && DesignItem.ContentProperty.IsCollection)
{
Expand All @@ -89,16 +91,31 @@ protected OutlineNodeBase(DesignItem designItem)
}
}

/// <summary>
/// Unsubscribes from DesignItem events to prevent memory leaks.
/// Called by derived classes during disposal.
/// </summary>
protected void DisposeEventHandlers()
{
if (DesignItem != null) {
DesignItem.NameChanged -= DesignItem_NameChanged;
DesignItem.PropertyChanged -= DesignItem_PropertyChanged;
if (DesignItem.ContentProperty != null && DesignItem.ContentProperty.IsCollection) {
DesignItem.ContentProperty.CollectionElements.CollectionChanged -= CollectionElements_CollectionChanged;
}
}
}

protected OutlineNodeBase(string name)
{
_name = name;
}

public DesignItem DesignItem { get; set; }

public virtual ServiceContainer Services
{
get { return this.DesignItem.Services; }
public virtual ServiceContainer Services
{
get { return this.DesignItem.Services; }
}

public ISelectionService SelectionService
Expand Down
18 changes: 10 additions & 8 deletions WpfDesign.Designer/Project/Xaml/XamlModelProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ void ResetInternal()
{
if (_property.IsSet)
{
var oldValue = _property.PropertyValue;
var oldValue = _property.PropertyValue;
_property.Reset();
_designItem.NotifyPropertyChanged(this, oldValue, null);
}
}
public override T GetConvertedValueOnInstance<T>() => _property.GetValueOnInstance<T>();
}

public override T GetConvertedValueOnInstance<T>() => _property.GetValueOnInstance<T>();

public sealed class PropertyChangeAction : ITransactionItem
{
readonly XamlModelProperty property;
Expand Down Expand Up @@ -331,11 +331,13 @@ public void Undo()
else {
if (property.DependencyProperty == null) {
try
{
{
property.SetValueOnInstance(oldValueOnInstance);
}
catch(Exception)
{ }
catch(Exception ex)
{
Debug.WriteLine($"SetValueOnInstance failed for {property.Name}: {ex.Message}");
}
}

property.ResetInternal();
Expand Down
4 changes: 3 additions & 1 deletion WpfDesign.XamlDom/Project/XamlObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,9 @@ BindingBase CopyBinding(BindingBase target)
var val2 = pd.GetValue(target);
if (object.Equals(val1, val2)) continue;
pd.SetValue(b, val2);
} catch {}
} catch (Exception ex) {
Debug.WriteLine($"CopyBinding failed for property {pd.Name}: {ex.Message}");
}
}

return b;
Expand Down
16 changes: 12 additions & 4 deletions WpfDesign.XamlDom/Project/XamlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,10 @@ internal static XamlPropertyInfo GetPropertyInfo(XamlTypeFinder typeFinder, obje
{
propertyInfo = FindProperty(elementInstance, propertyType, propertyName);
}
catch (Exception)
{ }
catch (Exception ex)
{
Debug.WriteLine($"FindProperty failed for {propertyType?.Name}.{propertyName}: {ex.Message}");
}
if (propertyInfo != null)
return propertyInfo;
}
Expand Down Expand Up @@ -857,8 +859,14 @@ public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSe
/// <returns>Returns the XamlObject of the parsed <paramref name="xaml"/>.</returns>
public static XamlObject ParseSnippet(XamlObject root, string xaml, XamlParserSettings settings, XamlObject parentObject)
{
XmlTextReader reader = new XmlTextReader(new StringReader(xaml));
var element = root.OwnerDocument.XmlDocument.ReadNode(reader);
var readerSettings = new XmlReaderSettings {
DtdProcessing = DtdProcessing.Prohibit,
XmlResolver = null
};
XmlNode element;
using (var reader = XmlReader.Create(new StringReader(xaml), readerSettings)) {
element = root.OwnerDocument.XmlDocument.ReadNode(reader);
}

if (element != null) {
XmlAttribute xmlnsAttribute=null;
Expand Down
6 changes: 4 additions & 2 deletions WpfDesign.XamlDom/Project/XamlProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,10 @@ public object DesignerValue {
return wr;
}
}
catch(Exception)
{ }
catch(Exception ex)
{
Debug.WriteLine($"DesignerValue.GetValueFor failed for {propertyInfo?.Name}: {ex.Message}");
}
var value = propertyInfo.GetValue(parentObject.Instance);
return value;
}
Expand Down
9 changes: 5 additions & 4 deletions WpfDesign.XamlDom/Project/XamlPropertyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public override object GetValue(object instance)
if (attachedGetter != null) {
return attachedGetter(instance);
}
} catch (Exception) {

} catch (Exception ex) {
Debug.WriteLine($"Attached property getter failed: {ex.Message}");
}

var dependencyObject = instance as DependencyObject;
Expand Down Expand Up @@ -175,8 +175,9 @@ public override void ResetValue(object instance)
{
try {
_propertyDescriptor.ResetValue(instance);
} catch (Exception) {
//For Example "UndoRedoSimpleBinding" will raise a exception here => look if it has Side Effects if we generally catch here?
} catch (Exception ex) {
// For Example "UndoRedoSimpleBinding" will raise an exception here
Debug.WriteLine($"ResetValue failed for {_propertyDescriptor.Name}: {ex.Message}");
}
}

Expand Down