Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Navigation in a Serivce locator pattern with a reusable view.

$
0
0

Hi,

I am hoping someone will be able to help me out with an mvvm light issue i am trying to overcome.

I have two and possibly more in the future database tables that are all identically except each will have a foreign key column that references different tables.

I need the users to be able to maintain data in these tables. The forms to maintain each table are identical.

My goal is to create one user control, a view model for each form that derives from a common abstract class or implements an common interface.

so far in my application i have used a ViewModelLocator/SimpleIoc pattern for navigation, this is working in the following manner:

A main view ( the menu view ) has DataTemplate bound to ViewModel properties on the ViewModeLocator as such:

        <DataTemplate DataType="{x:Type ViewModel:AViewModel}">
            <Views:AView/>
        </DataTemplate>

and a content control

        <ContentControl Grid.Row="1" Grid.Column="1" Margin="0" Content="{Binding CurrentView}">

        </ContentControl>

each of the underlying views has its data context defined as such:

DataContext="{Binding AViewModelInstance, Source={StaticResource Locator}}"

public AViewModel AViewModelInstance{ get { return ServiceLocator.Current.GetInstance<AViewModel >(); } }

I have buttons on the menu view which set the CurrentView variable to  a view model and the datatemplate defines which view is attached to that view model.

I'm not sure how to achieve my goal as I wont be able to define the datacontext in my xaml like this DataContext="{Binding AViewModelInstance, Source={StaticResource Locator}}" because the view will not be directly related to one view model instance.

Any direction would be appreciated.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>