Reza M.
Reza M.

Reputation: 1223

Dynamic Objects

Just curious as to how to modify a dynamic variable after creation.

I figure, I could just store them into some sort of list.

But I do assign them a name and event and wanted to know when the event is triggered would it be possible to modify the item with its name ?(object sender)

Edit Clarification:

On run time create new items and associate them with events.

Image img = new Image();
img.name = "Image" + someIntValue;
img.MouseDown += new MouseButtonEventHandler(selectedImageClick);
someGrid.Children.add(img);
void selectedImageClick(object sender, MouseButtonEventArgs e)
{
   //Modify that image e.g: border      
}

Upvotes: 0

Views: 210

Answers (1)

drovani
drovani

Reputation: 938

In order to modify the sender, you'll have to cast it. Your event handler would then look something like this:

void selectedImageClick(object sender, MouseButtonEventArgs e)
{
    Image img = sender as Image;
    if (img != null)  // In case someone calls this event handler with something other than an Image
    {
        //Modify that image e.g: border
    }
}

Upvotes: 2

Related Questions