Skip to main content

Microsoft Silverlight

Answered Question Events with Dynamic ControlsRSS Feed

(0)

DotNet_Expert
DotNet_E...

Member

Member

2 points

15 Posts

Events with Dynamic Controls

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
Sledge70

Contributor

Contributor

5988 points

1,050 Posts

Re: Events with Dynamic Controls

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/

______________________________________________________
Please mark replies as answers if they answered your question...

Flexman on Silverlight

DotNet_Expert
DotNet_E...

Member

Member

2 points

15 Posts

Re: Events with Dynamic Controls

could you or anyone provide a solution without any dependency of any third party tool...

Maud
Maud

Contributor

Contributor

3358 points

461 Posts

Answered Question

Re: Events with Dynamic Controls

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,

Maud
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities