Skip to content

Instantly share code, notes, and snippets.

@SchreinerK
Last active March 6, 2019 07:05
Show Gist options
  • Save SchreinerK/af4dd9ab0444139660ea646eedff2d6b to your computer and use it in GitHub Desktop.
Save SchreinerK/af4dd9ab0444139660ea646eedff2d6b to your computer and use it in GitHub Desktop.
Get all dependency and attached proprties
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