views:

32

answers:

2

My presenter defines its own view:

public SmartFormPresenter(SmartFormView view)
{
    View = view;
    View.DataContext = this;
}

In the view I have an element with x:Name="MainTabControl":

<DockPanel LastChildFill="True">
    <TabControl x:Name="MainTabControl" DockPanel.Dock="Top" ItemsSource="{Binding SmartFormAreaPresenters}">
        <TabControl.ItemContainerStyle>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="Header" Value="{Binding Title}"/>
            </Style>...

How can I access this element as I do in code behind, something like this:

PSEUDO-CODE:

View.Root.Children.MainTabControl.Visibility = Visibility.Collapsed;
A: 

Found it:

TabControl mainTabControl = View.FindName("MainTabControl") as TabControl;
mainTabControl.Visibility = Visibility.Hidden;
Edward Tanguay
+1  A: 

You can define a public property in your view that will expose the private field. Or better, don't do it and define some abstract property in your view, like "IsViewTabbed" or sth like this, that will abstract UI code out of presenter.

maciejkow
If I were doing an MVVM pattern I would *have* to abstract out a property. I understand that this is an advantage to having a Presenter instead of a ViewModel: that the Presenter intimately knows its View so you have the ability to reach in and change things manually if needed.
Edward Tanguay