0

I have x ListViews in my xaml Form:

  • name: lvExt1
  • name: lvExt2
  • etc...

In my program I can access them directly with lvExt1.Items or similar.

I would like to access those within a function that has the number as parameter

Something like:

privat void accessListView(string number){

   return lvlExt"number".Items;
}

In Symfony (PHP) I can do it like this: https://stackoverflow.com/a/31142123/1092632

I do realize it may be something completely different, but only to express what I am trying to do.

Community
  • 1
  • 1
PrimuS
  • 2,505
  • 6
  • 33
  • 66

1 Answers1

1

Two ways:

  1. Use the way that WPF provided:

    var lvlExt = this.FindName("lvlExt" + number) as ListView;

    var lvlExt = LogicalTreeHelper.FindLogicalNode(this, "lvlExt" + number);

  2. Use an array to reference:

    var lvlExts = new ListView[3];

    ...

    var lvlExt =ListView[number];

Newton Zou
  • 558
  • 1
  • 5
  • 20