Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change x:Name property inside xaml code using c# script?

Problem:

Using code need to add the XAML x:Name property to my ShellContentItem, that I’m creating inside AppShell.

Screenshots:

enter image description here

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

When adding an element in c#, you don’t "create an x:Name". Instead, you simplify define a property, and set that property to the element.

private ShellContent myItem;

    // Inside your method
    myItem = new ShellContent();
...

Now you access myItem like any other property.


If you wish to create and access a collection of items, you do that like any other kind of object in c#:

private List<ShellContent> myItems;

    // In method.
    myItems = new List<ShellContent>();
    for (...)
    {
        var item = new ShellContent();
        myItems.Add(item);
    }

Now access one like any other list: myItems[...].

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading