Get Markupextension expression in wpf via reflection

241 Views Asked by At

I try to parse WPF Custom Control with LogicalTreeHelper. The LogicalTreeHelper gives me each control as DependancyObject. And I need to investigate which static resources be used with a control.

The Example of an xaml:

<Label Grid.Row="0" Grid.Column="0" Margin="{StaticResource MarginExtraSmall}"
       VerticalAlignment="Center" Content="{x:Static p:Resources.Type}" ></Label>

The problem is, when I try to get a value of the "Content" property of the Control "Label", I recieve a string, but I need a markupextension expression insteed, in this case "{x:Static p:Resources.Type}"

Code:

DumpElement(object elem)
{
    var dependencyProperties = elem.GetType().GetDependencyProperties();
    DependencyObject dependencyObject = elem as DependencyObject;

    foreach (var dependencyProperty in dependencyProperties)
    {
      var binding = BindingOperations.GetBinding(dependencyObject, 
      dependencyProperty);
    }

    var publicProperties = elem.GetType().GetPublicProperies();

    foreach (var property in publicProperties)
    {
      var value = property.GetValue(elem);
    }
}

Have anybody an idea how to solve the problem?

0

There are 0 best solutions below