Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Events with Dynamic Controls
3 replies. Latest Post by Maud on November 5, 2009.
(0)
DotNet_E...
Member
3 points
16 Posts
11-03-2009 6:52 AM |
Hi All,
I have a class which is responsible to build the dynamic controls. in the same application i have different XAML pages which uses that class to create the controls as per their requirements. Now problem is that...
when it comes to attach the events to the controls: that event is in the XAML and control is being created in other class... so how i can pass the event to that class, keeping in mind that this class has only one function to build the controls and responsible to create almost 15 type of controls... so i can't pass 15 different events to the function.
but if i pass the complete object of XAML then it will no more a generic approach.
So guys could you please help me out in finding a way attach the events with controls in a generic manner.
all suggestions are welcome.
Sledge70
Contributor
5990 points
1,051 Posts
11-03-2009 7:55 AM |
It sounds as though the EventAggregator from Prism might be able to help you here.
This allows your controls to subscribe/publish events without having to be hardwired up.
It's generally used if you're using the MVVM pattern but could be useful in this scenario.
There are a lot of basic examples provided when you install prism. The eventing example may do what you require. Saves re-inventing the wheel.
http://www.sparklingclient.com/downloading-and-building-prism/
11-04-2009 2:11 AM |
could you or anyone provide a solution without any dependency of any third party tool...
Maud
3358 points
461 Posts
11-05-2009 1:22 AM |
Hi,
I'd like to know what kind of control you want to creat with uniform method?
If the 15 control has different functionality which need different code logic, then it's better to create usercontrol for each xaml, handling element event in codebehind file.
If 15 control xaml control has similar function, just different appearance, then you are definitely looking for creating Custom control, it's quite possible to create any kinds of appearance for control which should do the same logic. please check
http://msdn.microsoft.com/en-us/library/cc278064(VS.95).aspx
Thanks,