1

I have a series of textblocks with formulaic names such as "BlockOne", "BlockTwo", etc that are created in my XAML. I want to access the block names with text, ie:

if (output.Contains("206.218.192.186"))
{
    TextBlock + "One".Text = "AI";
}

How do I do this?

Craig W.
  • 17,838
  • 6
  • 49
  • 82
Sean
  • 336
  • 1
  • 3
  • 15

2 Answers2

1

You could use the FindName function, which lets you find a control, cast it your type, in this case TextBlock, and access it's Text value from there.

(TextBlock)this.FindName("myTextBlock").Text = "AI";
Kestami
  • 2,045
  • 3
  • 32
  • 47
0

Try using the FindName function of the parent container.

Here are some other posts that may expand on the details:

Find WPF control by Name

How can I find WPF controls by name or type?

Community
  • 1
  • 1
T. Yates
  • 192
  • 11