0

so i have wpf mvvm project and i want to pass data between view models. i craeate the window the the xaml of the window datacontex binding call to the lactor view model

DataContext="{Binding Source={StaticResource Locator}, Path=Game }"

and this is the lactor

        public ViewModelLocator()
    {
        ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
        SimpleIoc.Default.Register<MainViewModel>();
        SimpleIoc.Default.Register<GameViewModel>();
    }

    public MainViewModel Main
    {
        get
        {
            return ServiceLocator.Current.GetInstance<MainViewModel>();
        }
    }

    public GameViewModel Game
    {
        get
        {
            return ServiceLocator.Current.GetInstance<GameViewModel>();
        }
    }

cant pass for example a strig from main view model to game view model how can i do it ? thaks all

  • 2
    Use the [messenger](https://stackoverflow.com/questions/16993918/mvvm-light-messenger-sending-and-registering-objects)? – mm8 Aug 17 '21 at 15:21
  • Seems like XY problem .. There should be no need for such thing why you need it? ... **edit:** title is *wpf mvvm light pass some data **between vm with locator*** ... and in the question is *pass ... from **main view model to game view*** ... obviously "no need" for question in the title and for the question in body use messenger as mm8 wrote – Selvin Aug 17 '21 at 15:21

0 Answers0