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

Time:06-05

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

enter image description here

CodePudding user response:

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[...].

  • Related