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.

3
  • 1
    Try reading this Commented Nov 10, 2016 at 16:53
  • 1
    May be return (this.FindName("lvlExt" + number) as ListView).Items Commented Nov 10, 2016 at 17:15
  • or LogicalTreeHelper.FindLogicalNode(this, "lvlExt" + number) Commented Nov 10, 2016 at 17:19

1 Answer 1

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];

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.