Main and slave model interaction

Dec 26, 2010 at 4:32 PM

Hi, is it possible  set something like wpf window owner in caliburn.micro ?

I have MAIN VIEW MODEL, from this model I open SLAVE SCREEN {VIEW MODEL} with this method:

        public IEnumerable<IResult> Open()
        {

            yield return new ShowWindow("ChatScreen")
                .InitializeWith(_service
                .DetailData(Account, _selectedFriend.Value.Nick),
                AvatarImage);
        }

This method create a new WPF WINDOW - SLAVE SCREEN and initialize SLAVE VIEW MODEL with some variables.

I would like set something like this SLAVE_SCREEN.OWNER = MAIN_VIEW_MODEL.

I would like achieve if I close MAIN VIEW MODEL that it close also all SLAVE MODELS.

Also it exist way how can I check if screen, in my situation WPF window, is active/inactive from MAIN VIEW MODEL?

Coordinator
Dec 26, 2010 at 4:50 PM

You should look into how Conductors and Screens work. There's some extensive documentation on this now.

Dec 28, 2010 at 3:24 PM
Edited Dec 28, 2010 at 3:42 PM
EisenbergEffect wrote:

You should look into how Conductors and Screens work. There's some extensive documentation on this now.

Hi, thank for advice, but I am little confuse.

First,I try this:

Main screen:

    [Export("MessengerScreen", typeof(IMessengerViewModel))]
    public class MessengerViewModel : Screen, IViewModelIdentity,
        IMessengerViewModel, IInitializableWithOneArg<Account>, IHandle<Rp>
    {
        //contains active screen
        private Dictionary<string, object> _activeScreen;
   
        //open screen
        public IEnumerable<IResult> OpenChatScreen()
        {
            //dic doesn’t contains chatScreen
            if (!_activeScreen.ContainsKey(_selectedFriend.Value.Nick))
            {
                var chatScreen = new ShowWindow("ChatScreen")
                                           .InitializeWith(_service.DetailData(Account, _selectedFriend.Value.Nick),
                                           AvatarImage);
   
                //add to dic
                _activeScreen.Add(_selectedFriend.Value.Nick, chatScreen);
   
                yield return chatScreen;
            }
        }
    }




ChatScreen:

    [Export("ChatScreen",typeof(IChatViewModel))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class ChatViewModel : Screen, IViewModelIdentity,
        IInitializableWithTwoArgs<DetailData, BitmapImage>, IHandle<Rp>
    {...}




I don’t that is suitable solution have dictionary in main view model. But I have problem how remove chat screen from dictionary if chat screen is deactivate. Ok, I can use event aggregator, and publish from chat screen on messenger screen,when is chat screen deactivated, but I think that is bad way.