Last active
March 6, 2019 07:05
-
-
Save SchreinerK/af4dd9ab0444139660ea646eedff2d6b to your computer and use it in GitHub Desktop.
Get all dependency and attached proprties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Windows; | |
using System.Windows.Controls.Primitives; | |
using System.Windows.Markup.Primitives; | |
using System.Windows.Media; | |
public static class DependencyObjectExtensions | |
{ | |
public static List<DependencyProperty> GetDependencyProperties(this DependencyObject element) | |
{ | |
var properties = new List<DependencyProperty>(); | |
var markupObject = MarkupWriter.GetMarkupObjectFor(element); | |
foreach (var mp in markupObject.Properties) | |
{ | |
if (mp.DependencyProperty != null) | |
{ | |
properties.Add(mp.DependencyProperty); | |
} | |
} | |
return properties; | |
} | |
public static List<DependencyProperty> GetAttachedProperties(this DependencyObject element) | |
{ | |
var attachedProperties = new List<DependencyProperty>(); | |
var markupObject = MarkupWriter.GetMarkupObjectFor(element); | |
foreach (var mp in markupObject.Properties) | |
{ | |
if (mp.IsAttached) | |
{ | |
attachedProperties.Add(mp.DependencyProperty); | |
} | |
} | |
return attachedProperties; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment