tags:

views:

40

answers:

1

Hello,

I'm using WPF and the Tab Control as my menu. This generate alot of code behind code because one file is controlling all the user actions. Then i was thinking that i could use a Controller class for every TabItem. I used it and it works, but dont like the outcome. I have to use the FindName() method on the TabItem that i pass to the Controller and it generates some ugly code that can be hard to debug (in my opinion at least).

So is there anyway to pass the TabItem so i can find the Controls on the xaml page in my Controller?

For example i have TabItem1, TabItem2 and TabItem3. Each containing a page for the user to use. Then i want to pass TabItem1 to controller TabItem1Controller. At the moment im doing it this way:

public TurbineController(TabItem tab)
    {
        _client = tab;
    }

But then i have to use the FindName() method.

Is my request possible?

A: 

You got it backward, at least to the MVVM approach. The controller (TurbineContoller) shouldn't reference the view (TabItem), the view should reference the controller. Create a collection of controllers and databind the collection to a tabcontrol. The datacontext of each tab will be the controller which the tab will databind to.

Wallstreet Programmer