More time delay occurs when getting attached properties using MarkupWriter

Magesh Sankar 36 Reputation points
2021-01-27T13:04:08.3+00:00

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?

Code:

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

        Class1 viewmodel = new Class1();
        timer = new Stopwatch();
        timer.Start();
        //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());
            timer.Stop();
        }
    }
}

Sample Link:
https://drive.google.com/file/d/1sUxg3rwZQrOkdQmOWT6Xocb7w2SgJdmF/view?usp=sharing

Scrennshot:
enter image description here

For 600 properties it almost taking 600 ms time to fetch

Any suggestion to reduce time delay.

Thanks

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,691 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
775 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. DaisyTian-1203 11,616 Reputation points
    2021-01-28T06:45:12.723+00:00

    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:
    61233-capture2.png

    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
    61334-capture.png


    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.