0

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?

Richard
  • 439
  • 3
  • 25
  • Make sure that GisViewModel is not null. – Clemens Nov 11 '22 at 11:09
  • Of course, feel daft now. It was because I hadn't registered the overarching ViewModel in the IOC so the GISViewModel couldn't be injected. All sorted now. Thanks – Richard Nov 11 '22 at 11:53

0 Answers0