Richard
Richard

Reputation: 509

Injected ViewModels are not visible in a WPF content control unless re-initialised

I have a content control as follows:

<ContentControl 
    x:Name="GraphArea"
    s:View.Model="{Binding SelectedViewModel}"
    VerticalContentAlignment="Stretch" 
    HorizontalContentAlignment="Stretch" />

This binds to the following property in my ViewModel:

private Screen selectedViewModel;

public Screen SelectedViewModel
    {
        get { return selectedViewModel; }
        set{SetAndNotify(ref this.selectedViewModel, value);}
    }

I then have a second ViewModel called GisViewModel which is injected as follows using Stylet.

[Inject]
public GisViewModel GisViewModel { get; set; }

I then insert my GisViewModel into my SelectedViewModel property as follows:

public void LoadMap()
    {
        SelectedViewModel = GisViewModel;
    }

But doing this displays nothing in the ContentControl.

If however I do the following, the content control loads great, but I don't want to create a new GISViewModel just to view it.

public void LoadMap()
    {
        SelectedViewModel = new GisViewModel();
    }

Why is the newly initiallised GisViewModel visible in my content control, but not the injected version?

Upvotes: 0

Views: 50

Answers (0)

Related Questions