Browse Source

Merge pull request #660 from gumme/WpfDesignerWarningFixes

Wpf designer warning fixes
pull/664/head
Andreas Weizel 11 years ago
parent
commit
b1d3139740
  1. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  2. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs
  3. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs
  4. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs
  5. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs
  6. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeBase.cs
  7. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
  8. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/TemplateHelper.cs
  9. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs
  10. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs
  11. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  12. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  13. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlTypeFinder.cs
  14. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs
  15. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemExtension.cs
  16. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DummyValueInsteadOfNullTypeDescriptionProvider.cs
  17. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/Extension.cs
  18. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionAttribute.cs
  19. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionServer.cs
  20. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/SelectionExtensionServer.cs
  21. 29
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/UIExtensions/UIHelpers.cs

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

@ -35,7 +35,6 @@ using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.UIExtensions; using ICSharpCode.WpfDesign.UIExtensions;
using ICSharpCode.WpfDesign.Designer.Xaml; using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Extensions; using ICSharpCode.WpfDesign.Extensions;
using System.Linq;
namespace ICSharpCode.WpfDesign.Designer namespace ICSharpCode.WpfDesign.Designer
{ {

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs

@ -82,7 +82,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
private ChangeGroup changeGroup; private ChangeGroup changeGroup;
private DesignItem newLine; private DesignItem newLine;
private Point startPoint; private new Point startPoint;
public DrawPolylineMouseGesture(DesignItem newLine, IInputElement relativeTo, ChangeGroup changeGroup) public DrawPolylineMouseGesture(DesignItem newLine, IInputElement relativeTo, ChangeGroup changeGroup)
{ {

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PartialPanelSelectionHandler.cs

@ -39,7 +39,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
this.ExtendedItem.AddBehavior(typeof(IHandlePointerToolMouseDown), this); this.ExtendedItem.AddBehavior(typeof(IHandlePointerToolMouseDown), this);
} }
public new void HandleSelectionMouseDown(IDesignPanel designPanel, MouseButtonEventArgs e, DesignPanelHitTestResult result) #region IHandlePointerToolMouseDown
public void HandleSelectionMouseDown(IDesignPanel designPanel, MouseButtonEventArgs e, DesignPanelHitTestResult result)
{ {
if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left))
{ {
@ -47,6 +49,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
new PartialRangeSelectionGesture(result.ModelHit).Start(designPanel, e); new PartialRangeSelectionGesture(result.ModelHit).Start(designPanel, e);
} }
} }
#endregion
} }
/// <summary> /// <summary>

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs

@ -160,7 +160,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
} }
private readonly Dictionary<int, Bounds> _selectedThumbs = new Dictionary<int, Bounds>(); private readonly Dictionary<int, Bounds> _selectedThumbs = new Dictionary<int, Bounds>();
#pragma warning disable 0414 // For future use, disable Warning CS0414: The field is assigned but its value is never used
private bool _isDragging; private bool _isDragging;
#pragma warning restore 0414
ZoomControl _zoom; ZoomControl _zoom;
private List<PathPoint> pathPoints = null; private List<PathPoint> pathPoints = null;

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs

@ -47,7 +47,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize) public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{ {
Point p = new Point(0, 0); Point p = new Point(0, 0);
double distance = 0;
if (shape is Line) if (shape is Line)
{ {
var s = shape as Line; var s = shape as Line;

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineNodeBase.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
} }
catch (Exception) catch (Exception)
{ } { }
if (hidden != null && (bool)hidden) { if (hidden) {
_isDesignTimeVisible = false; _isDesignTimeVisible = false;
((FrameworkElement)DesignItem.Component).Visibility = Visibility.Hidden; ((FrameworkElement)DesignItem.Component).Visibility = Visibility.Hidden;
} }
@ -50,7 +50,7 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
} }
catch (Exception) catch (Exception)
{ } { }
if (locked != null && (bool)locked) { if (locked) {
_isDesignTimeLocked = true; _isDesignTimeLocked = true;
} }

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

@ -86,7 +86,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
} else if (collectionInstance is IDictionary) { } else if (collectionInstance is IDictionary) {
object val = newElement.GetValueFor(null); object val = newElement.GetValueFor(null);
object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null; object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null;
if (key == null || key == "") if (key == null || (key as string) == "")
{ {
if (val is Style) if (val is Style)
key = ((Style)val).TargetType; key = ((Style)val).TargetType;
@ -150,8 +150,6 @@ namespace ICSharpCode.WpfDesign.XamlDom
} catch (MissingMethodException) { } catch (MissingMethodException) {
return false; return false;
} }
return true;
} }
static readonly Type[] RemoveAtParameters = { typeof(int) }; static readonly Type[] RemoveAtParameters = { typeof(int) };

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/TemplateHelper.cs

@ -31,8 +31,17 @@ using System.Xml.XPath;
namespace ICSharpCode.WpfDesign.XamlDom namespace ICSharpCode.WpfDesign.XamlDom
{ {
/// <summary>
/// Contains template related helper methods.
/// </summary>
public static class TemplateHelper public static class TemplateHelper
{ {
/// <summary>
/// Gets a <see cref="FrameworkTemplate"/> based on the specified parameters.
/// </summary>
/// <param name="xmlElement">The xml element to get template xaml from.</param>
/// <param name="parentObject">The <see cref="XamlObject"/> to use as source for resources and contextual information.</param>
/// <returns>A <see cref="FrameworkTemplate"/> based on the specified parameters.</returns>
public static FrameworkTemplate GetFrameworkTemplate(XmlElement xmlElement, XamlObject parentObject) public static FrameworkTemplate GetFrameworkTemplate(XmlElement xmlElement, XamlObject parentObject)
{ {

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

@ -206,6 +206,10 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
private XamlType _systemXamlTypeForProperty = null; private XamlType _systemXamlTypeForProperty = null;
/// <summary>
/// Gets a <see cref="XamlType"/> representing the <see cref="XamlObject.ElementType"/>.
/// </summary>
public XamlType SystemXamlTypeForProperty public XamlType SystemXamlTypeForProperty
{ {
get get

16
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs

@ -127,6 +127,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
#region IUriContext implementation #region IUriContext implementation
/// <inheritdoc/>
public virtual Uri BaseUri { public virtual Uri BaseUri {
get { get {
return new Uri("pack://application:,,,/"); return new Uri("pack://application:,,,/");
@ -151,6 +152,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
// } // }
//} //}
/// <inheritdoc/>
public XamlSchemaContext SchemaContext public XamlSchemaContext SchemaContext
{ {
get get
@ -163,16 +165,19 @@ namespace ICSharpCode.WpfDesign.XamlDom
#region IAmbientProvider Members #region IAmbientProvider Members
/// <inheritdoc/>
public AmbientPropertyValue GetFirstAmbientValue(IEnumerable<XamlType> ceilingTypes, params XamlMember[] properties) public AmbientPropertyValue GetFirstAmbientValue(IEnumerable<XamlType> ceilingTypes, params XamlMember[] properties)
{ {
return GetAllAmbientValues(ceilingTypes, properties).FirstOrDefault(); return GetAllAmbientValues(ceilingTypes, properties).FirstOrDefault();
} }
/// <inheritdoc/>
public object GetFirstAmbientValue(params XamlType[] types) public object GetFirstAmbientValue(params XamlType[] types)
{ {
return null; return null;
} }
/// <inheritdoc/>
public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, params XamlMember[] properties) public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, params XamlMember[] properties)
{ {
var obj = this.XamlObject.ParentObject; var obj = this.XamlObject.ParentObject;
@ -194,11 +199,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
} }
/// <inheritdoc/>
public IEnumerable<object> GetAllAmbientValues(params XamlType[] types) public IEnumerable<object> GetAllAmbientValues(params XamlType[] types)
{ {
return new List<object>(); return new List<object>();
} }
/// <inheritdoc/>
public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, bool searchLiveStackOnly, IEnumerable<XamlType> types, params XamlMember[] properties) public IEnumerable<AmbientPropertyValue> GetAllAmbientValues(IEnumerable<XamlType> ceilingTypes, bool searchLiveStackOnly, IEnumerable<XamlType> types, params XamlMember[] properties)
{ {
return new List<AmbientPropertyValue>(); return new List<AmbientPropertyValue>();
@ -208,6 +215,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
#region IXamlNameResolver #region IXamlNameResolver
/// <inheritdoc/>
public object Resolve(string name) public object Resolve(string name)
{ {
INameScope ns = null; INameScope ns = null;
@ -228,6 +236,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
return null; return null;
} }
/// <inheritdoc/>
public object Resolve(string name, out bool isFullyInitialized) public object Resolve(string name, out bool isFullyInitialized)
{ {
var ret = Resolve(name); var ret = Resolve(name);
@ -235,27 +244,34 @@ namespace ICSharpCode.WpfDesign.XamlDom
return ret; return ret;
} }
/// <inheritdoc/>
public object GetFixupToken(IEnumerable<string> names) public object GetFixupToken(IEnumerable<string> names)
{ {
return null; return null;
} }
/// <inheritdoc/>
public object GetFixupToken(IEnumerable<string> names, bool canAssignDirectly) public object GetFixupToken(IEnumerable<string> names, bool canAssignDirectly)
{ {
return null; return null;
} }
/// <inheritdoc/>
public IEnumerable<KeyValuePair<string, object>> GetAllNamesAndValuesInScope() public IEnumerable<KeyValuePair<string, object>> GetAllNamesAndValuesInScope()
{ {
return null; return null;
} }
/// <inheritdoc/>
public bool IsFixupTokenAvailable public bool IsFixupTokenAvailable
{ {
get { return false; } get { return false; }
} }
#pragma warning disable 0067 // Required by interface implementation, disable Warning CS0067: The event is never used
/// <inheritdoc/>
public event EventHandler OnNameScopeInitializationComplete; public event EventHandler OnNameScopeInitializationComplete;
#pragma warning restore 0067
#endregion #endregion
} }

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

@ -607,7 +607,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
{ {
propertyInfo = FindProperty(elementInstance, propertyType, propertyName); propertyInfo = FindProperty(elementInstance, propertyType, propertyName);
} }
catch (Exception ex) catch (Exception)
{ } { }
if (propertyInfo != null) if (propertyInfo != null)
return propertyInfo; return propertyInfo;

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

@ -270,6 +270,10 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
private XamlMember _systemXamlMemberForProperty = null; private XamlMember _systemXamlMemberForProperty = null;
/// <summary>
/// Gets a <see cref="XamlMember"/> representing the property.
/// </summary>
public XamlMember SystemXamlMemberForProperty public XamlMember SystemXamlMemberForProperty
{ {
get get
@ -281,6 +285,10 @@ namespace ICSharpCode.WpfDesign.XamlDom
} }
private XamlType _systemXamlTypeForProperty = null; private XamlType _systemXamlTypeForProperty = null;
/// <summary>
/// Gets a <see cref="XamlType"/> representing the type the property is declared on.
/// </summary>
public XamlType SystemXamlTypeForProperty public XamlType SystemXamlTypeForProperty
{ {
get get

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

@ -304,6 +304,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
return WpfTypeFinder.Instance.Clone(); return WpfTypeFinder.Instance.Clone();
} }
/// <summary>
/// Converts the specified <see cref="Uri"/> to local.
/// </summary>
public virtual Uri ConvertUriToLocalUri(Uri uri) public virtual Uri ConvertUriToLocalUri(Uri uri)
{ {
return uri; return uri;

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

@ -199,6 +199,9 @@ namespace ICSharpCode.WpfDesign
} }
} }
/// <summary>
/// Reapplies all extensions.
/// </summary>
public void ReapplyAllExtensions() public void ReapplyAllExtensions()
{ {
var manager = this.Services.GetService<Extensions.ExtensionManager>(); var manager = this.Services.GetService<Extensions.ExtensionManager>();
@ -293,6 +296,9 @@ namespace ICSharpCode.WpfDesign
/// </summary> /// </summary>
public abstract DesignItem Clone(); public abstract DesignItem Clone();
/// <summary>
/// Gets a <see cref="Transform"/> that represents all transforms applied to the item's view.
/// </summary>
public Transform GetCompleteAppliedTransformationToView() public Transform GetCompleteAppliedTransformationToView()
{ {
var retVal = new TransformGroup(); var retVal = new TransformGroup();

13
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemExtension.cs

@ -29,7 +29,20 @@ namespace ICSharpCode.WpfDesign
/// </summary> /// </summary>
public interface IDrawItemExtension public interface IDrawItemExtension
{ {
/// <summary>
/// Returns if the specified type can be drawn.
/// </summary>
/// <param name="createItemType">The type to check.</param>
/// <returns>True if the specified type can be drawn, otherwise false.</returns>
bool CanItemBeDrawn(Type createItemType); bool CanItemBeDrawn(Type createItemType);
/// <summary>
/// Starts to draw.
/// </summary>
/// <param name="clickedOn">The item.</param>
/// <param name="createItemType">The item type.</param>
/// <param name="panel">The design panel to draw on.</param>
/// <param name="e">The <see cref="MouseEventArgs"/> argument that initiated the draw operation.</param>
void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, MouseEventArgs e); void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, MouseEventArgs e);
} }
} }

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

@ -35,6 +35,9 @@ namespace ICSharpCode.WpfDesign
readonly string _propertyName; readonly string _propertyName;
readonly object _dummyValue; readonly object _dummyValue;
/// <summary>
/// Initializes a new instance of <see cref="DummyValueInsteadOfNullTypeDescriptionProvider"/>.
/// </summary>
public DummyValueInsteadOfNullTypeDescriptionProvider(TypeDescriptionProvider existingProvider, public DummyValueInsteadOfNullTypeDescriptionProvider(TypeDescriptionProvider existingProvider,
string propertyName, object dummyValue) string propertyName, object dummyValue)
: base(existingProvider) : base(existingProvider)
@ -43,6 +46,7 @@ namespace ICSharpCode.WpfDesign
this._dummyValue = dummyValue; this._dummyValue = dummyValue;
} }
/// <inheritdoc/>
public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance)
{ {
return new ShadowTypeDescriptor(this, base.GetTypeDescriptor(objectType, instance)); return new ShadowTypeDescriptor(this, base.GetTypeDescriptor(objectType, instance));

13
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/Extension.cs

@ -33,16 +33,29 @@ namespace ICSharpCode.WpfDesign.Extensions
/// </remarks> /// </remarks>
public abstract class Extension public abstract class Extension
{ {
/// <summary>
/// Gets the value of the <see cref="DisabledExtensionsProperty"/> attached property for an object.
/// </summary>
/// <param name="obj">The object from which the property value is read.</param>
/// <returns>The object's <see cref="DisabledExtensionsProperty"/> property value.</returns>
public static string GetDisabledExtensions(DependencyObject obj) public static string GetDisabledExtensions(DependencyObject obj)
{ {
return (string)obj.GetValue(DisabledExtensionsProperty); return (string)obj.GetValue(DisabledExtensionsProperty);
} }
/// <summary>
/// Sets the value of the <see cref="DisabledExtensionsProperty"/> attached property for an object.
/// </summary>
/// <param name="obj">The object to which the attached property is written.</param>
/// <param name="value">The value to set.</param>
public static void SetDisabledExtensions(DependencyObject obj, string value) public static void SetDisabledExtensions(DependencyObject obj, string value)
{ {
obj.SetValue(DisabledExtensionsProperty, value); obj.SetValue(DisabledExtensionsProperty, value);
} }
/// <summary>
/// Gets or sets a semicolon-separated list with extension names that is disabled for a component's view.
/// </summary>
public static readonly DependencyProperty DisabledExtensionsProperty = public static readonly DependencyProperty DisabledExtensionsProperty =
DependencyProperty.RegisterAttached("DisabledExtensions", typeof(string), typeof(Extension), new PropertyMetadata(null)); DependencyProperty.RegisterAttached("DisabledExtensions", typeof(string), typeof(Extension), new PropertyMetadata(null));

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionAttribute.cs

@ -26,7 +26,9 @@ namespace ICSharpCode.WpfDesign.Extensions
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=false)] [AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
public sealed class ExtensionAttribute : Attribute public sealed class ExtensionAttribute : Attribute
{ {
//The Order in wich the Extensions are used /// <summary>
/// Gets or sets the Order in wich the extensions are used.
/// </summary>
public int Order { get; set; } public int Order { get; set; }
} }
} }

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/ExtensionServer.cs

@ -74,8 +74,8 @@ namespace ICSharpCode.WpfDesign.Extensions
/// </summary> /// </summary>
public abstract bool ShouldApplyExtensions(DesignItem extendedItem); public abstract bool ShouldApplyExtensions(DesignItem extendedItem);
// <summary> /// <summary>
/// Set if the Extension Server should be reaplied (For multiple Selection extension Server for Example!) /// Returns if the Extension Server should be reapplied (for multiple selection extension server for example).
/// </summary> /// </summary>
public virtual bool ShouldBeReApplied() public virtual bool ShouldBeReApplied()
{ {

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Extensions/SelectionExtensionServer.cs

@ -121,6 +121,7 @@ namespace ICSharpCode.WpfDesign.Extensions
ReapplyExtensions(this.Services.Selection.SelectedItems); ReapplyExtensions(this.Services.Selection.SelectedItems);
} }
/// <inheritdoc/>
public override bool ShouldBeReApplied() public override bool ShouldBeReApplied()
{ {
return true; return true;

29
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/UIExtensions/UIHelpers.cs

@ -25,8 +25,17 @@ using System.Windows.Media;
namespace ICSharpCode.WpfDesign.UIExtensions namespace ICSharpCode.WpfDesign.UIExtensions
{ {
/// <summary>
/// Contains helper methods for UI.
/// </summary>
public static class UIHelpers public static class UIHelpers
{ {
/// <summary>
/// Gets the parent. Which tree the parent is retrieved from depends on the parameters.
/// </summary>
/// <param name="child">The child to get parent for.</param>
/// <param name="searchCompleteVisualTree">If true the parent in the visual tree is returned, if false the parent may be retrieved from another tree depending on the child type.</param>
/// <returns>The parent element, and depending on the parameters its retrieved from either visual tree, logical tree or a tree not strictly speaking either the logical tree or the visual tree.</returns>
public static DependencyObject GetParentObject(this DependencyObject child, bool searchCompleteVisualTree) public static DependencyObject GetParentObject(this DependencyObject child, bool searchCompleteVisualTree)
{ {
if (child == null) return null; if (child == null) return null;
@ -53,6 +62,15 @@ namespace ICSharpCode.WpfDesign.UIExtensions
return VisualTreeHelper.GetParent(child); return VisualTreeHelper.GetParent(child);
} }
/// <summary>
/// Gets first parent element of the specified type. Which tree the parent is retrieved from depends on the parameters.
/// </summary>
/// <param name="child">The child to get parent for.</param>
/// <param name="searchCompleteVisualTree">If true the parent in the visual tree is returned, if false the parent may be retrieved from another tree depending on the child type.</param>
/// <returns>
/// The first parent element of the specified type, and depending on the parameters its retrieved from either visual tree, logical tree or a tree not strictly speaking either the logical tree or the visual tree.
/// null is returned if no parent of the specified type is found.
/// </returns>
public static T TryFindParent<T>(this DependencyObject child, bool searchCompleteVisualTree = false) where T : DependencyObject public static T TryFindParent<T>(this DependencyObject child, bool searchCompleteVisualTree = false) where T : DependencyObject
{ {
DependencyObject parentObject = GetParentObject(child, searchCompleteVisualTree); DependencyObject parentObject = GetParentObject(child, searchCompleteVisualTree);
@ -68,6 +86,11 @@ namespace ICSharpCode.WpfDesign.UIExtensions
return TryFindParent<T>(parentObject); return TryFindParent<T>(parentObject);
} }
/// <summary>
/// Returns the first child of the specified type found in the visual tree.
/// </summary>
/// <param name="parent">The parent element where the search is started.</param>
/// <returns>The first child of the specified type found in the visual tree, or null if no parent of the specified type is found.</returns>
public static T TryFindChild<T>(this DependencyObject parent) where T : DependencyObject public static T TryFindChild<T>(this DependencyObject parent) where T : DependencyObject
{ {
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++) for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
@ -87,6 +110,12 @@ namespace ICSharpCode.WpfDesign.UIExtensions
return null; return null;
} }
/// <summary>
/// Returns the first child of the specified type and with the specified name found in the visual tree.
/// </summary>
/// <param name="parent">The parent element where the search is started.</param>
/// <param name="childName">The name of the child element to find, or an empty string or null to only look at the type.</param>
/// <returns>The first child that matches the specified type and child name, or null if no match is found.</returns>
public static T TryFindChild<T>(this DependencyObject parent, string childName) where T : DependencyObject public static T TryFindChild<T>(this DependencyObject parent, string childName) where T : DependencyObject
{ {
if (parent == null) return null; if (parent == null) return null;

Loading…
Cancel
Save