Tech Talk A software developer on all things tech, and then some

8Sep/110

An Interesting Way to Use The FrameWork Element, Tag

The other day I needed to send an object with a control for a dashboard type interface. I started messing around with the tag and realized in .Net 4.0 and WPF, it can hold an object, not just text. So let's say I had an object ControlInfo. I then wanted to added that to the control using the tag, I would do something like the following.

private void SomeAddControlFunction(object sender)
{
   Control control = sender as Control;

   ControlInfo NewControlInfo = new ControlInfo();
   NewControlInfo.Name = "Test Name";
   NewControlInfo.Desc = "Test Desc";

   control.Tag = NewControlInfo;
}

private void SomeClickEventFunction(Object sender, RoutedEventArgs e)
{
   Control InControl = sender as Control;
   ControlInfo InControlInfo = InControl.Tag as ControlInfo;

   //Now we can use the object for whatever we need.
}

Comments (0) Trackbacks (0)

No comments yet.


Leave a Reply

No trackbacks yet.

%d bloggers like this: