More time delay occurs when getting attached properties using MarkupWriter

Magesh Sankar 36 Reputation points

I have trying to get the attached properties of a custom class which contain 1000 plus properties using MarkUpWriter. But when using MarkUpWriter for retrieving attached properties it causes more time delay. Please find the sample and screenshot regarding it below

Can you please provide any work around solution for reducing time delay or any other solution for getting attached properties of an custom class?


 public partial class MainWindow : Window
    private Stopwatch timer;
    public MainWindow()

        Class1 viewmodel = new Class1();
        timer = new Stopwatch();
        //Codes to get the attached properties descriptors.
       Dictionary<PropertyDescriptor, DependencyProperty> markUpPropertiesList = new Dictionary<PropertyDescriptor, DependencyProperty>();
        MarkupObject markupObject = MarkupWriter.GetMarkupObjectFor(viewmodel);
        if (markupObject != null && markupObject.Properties != null && markupObject.Properties.Any())
            foreach (MarkupProperty markupProperty in markupObject.Properties)
                if (markupProperty.IsAttached && !markupProperty.IsComposite)
                    markUpPropertiesList.Add(markupProperty.PropertyDescriptor, markupProperty.DependencyProperty);

            MessageBox.Show("Properties Count---"+ markupObject.Properties.Count().ToString() + "\n"+ "Total Milliseconds----"+ timer.ElapsedMilliseconds.ToString());

Sample Link:

enter image description here

For 600 properties it almost taking 600 ms time to fetch

Any suggestion to reduce time delay.


Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,686 questions
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
770 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. DaisyTian-1203 11,616 Reputation points

    I tested your project in my device and got less running time than you do. This may have something to do with the environment in which the computer is running. Here is my result picture:

    GetMarkupObjectFor needs time to find the properties, and you can check its details in here.How about to use viewmodel.GetType().GetProperties() to get the property, then you can remove the relevant Properties according to your requirements. here is its running picture

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.