Reputation: 490
In my C# project, I have a standard form with 5 tabs. Each tab provides controls to perform some functions. I need advice on how to design classes so that I can handle displaying of tabs and logic to peform actions in them. Any specific UI design pattern that I can use here?
Problem is 1. Currently all the events are subscribed in Main form. So the file becomes more complex to maintain. 2. Also every time we have to check which tab is currently displayed based on which I need to perform some action. This makes it more complicated.
So I am primarily looking on doing a good design for event & logic handling with this User interface. (Note I am using standard controls not WPF)
Upvotes: 0
Views: 181
Reputation: 4104
Have you looked into using PRISM? This may help solve your problems; it is mainly for WPF, but you can get the source code and pull the EventAggregator source.
Using the EventAggregator would allow you to publish / subscribe events based on a type; e.g. you declare the event like so:
public class SomethingHappenedEvent : PubSubEvent<DataToSendType>
{
}
subscribers can listen for events like so in a method you've defined:
_eventAggregator.GetEvent<SomethingHappenedEvent>().Subscribe(OnSomethingHappened);
public void OnSomethingHappened(DataToSendType data)
{
//process data
}
then when the user takes does something that you need to notify a subscriber of, your code can publish it to all subscribers:
_eventAggregator.GetEvent<SomethingHappenedEvent>().Publish(data);
You could then move the business logic into separate classes and make it testable outside of the UI; it would then lend itself to a migration to MVVM should the need arise.
Complete documentation is here.
Upvotes: 1