C# is not like JavaScript
You used the code document.getElementById('#name')
to show your intent. Let us analyze what exactly JS does when it it executes this line. It searches your entire DOM for an object with the ID name and returns a reference to it.
C# does not operate like that. There is no easily searchable pile of objects somewhere, where you just need to perform a query and get the object you want. If you want to keep a list of objects, you have to make that list yourself.
I assume you are creating several TextBlock
-objects. When you do that, you need to add them to a list, which you can then query. Here is a sample implementation:
List<TextBlock> textBlocks = new List<TextBlock>();
private TextBlock GetTextBlockByName(string name)
{
if(name == null) return null; //I assume that a TextBlock needs to have a name.
// Returns the TextBlock if it was found or null if not.
// Throws an Exception if more than one TextBlock has the same name
return this.textBlocks.Find(t => t.Name == name).SingleOrDefault();
}
A friendly hint for you, since I assume you are not extremely proficient with C# yet: When you come to a new programming language, don't assume that it follows the exact same paradigms that other languages you know follow, even if they occassionally have similarities. The whole reason we have so many different languages is that some things are easy in one, and difficult in another.