Click here to Skip to main content
14,665,452 members
Rate this:
Please Sign up or sign in to vote.
See more:
Please help, i need this to know for my school exam next week!!!

I am creating an Email Client in WPF, so far i have a List<> with messages, for each message is created a user control with a unique tag(1,2,3,..) and data inside the form. The user controls are added dynamically in a wrap panel depends on the number of messages.

Something like this:[^]

I want to raise an event on the user control, for example open a bigger window with the data from the user control.

How should i raise the event, should i create somekind of custom event, becose i need to compare the tag of the usercontrol created in main window so it matches and opens the correct window?
Updated 27-Nov-14 12:43pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

It would likely help if you posted the code you have for generating the dynamic controls; however, wiring up the events is pretty simple.

For example you can do something like this:

MyUserControl ctl = new MyUserContro();
ctl.MouseRaisedEvent += new ...

and in your user control you have properties to expose the events. An example is at[^]
BiggiSmalls 28-Nov-14 7:02am
This is the code for dynamically generating user controls:

//Message is the class with properties and List<> listofMessages
foreach (Message item in Message.listofMessages)
UserCKocka novUc = new UserCKocka();
novUc.Margin = new Thickness(5);
novUc.Width = 180;
novUc.Height = 180;

//Increase tag number
//Tag user control with the number stTaga
novUc.Tag = stTaga;

//Adding the datas and image for the newly created user control
Uri slikaPot = new Uri(item.Slika, UriKind.RelativeOrAbsolute);
BitmapImage slika = new BitmapImage(slikaPot);
novUc.slikaKocka.Source = slika;

//Textblock pošiljatelj
novUc.txtPosiljateljKocka.Text = item.Od;
novUc.txtZadevaKocka.Text = item.Zadeva;
novUc.SporociloKocka.Text = item.Vsebina;


Thank you for helping me :)

Can you help me little more? How do check which user control is clicked by its Tag, in case if i wanted to delete it??
ZurdoDev 28-Nov-14 9:29am
In the raised event you can check the tag property.
BiggiSmalls 28-Nov-14 13:41pm
Thank you very much :) i figured it out. Have a nice day
ZurdoDev 28-Nov-14 14:02pm
Glad to hear it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100