0

So I have this MVVM app, and in one of the Views called RedView with its corresponding RedViewModel

Inside RedView there is a button :

<Button Content="OpenSmallWindow" Style="{DynamicResource appButton}" Grid.Column="1" x:Name="ShowSmallWindow" />

and inside RedViewModel the code for it :

public void ShowSmallWindow()
        {
            Window window = new Window
            {
                Title = "SmallWindow",
                Content = new SmallWindowView(),
                SizeToContent = SizeToContent.WidthAndHeight,
                ResizeMode = ResizeMode.NoResize

            };
            window.Show();

Inside the code I can correctly display the SmallWindowView when the button is clicked. However on each press of the button a new small window appears on each click which is not what I wanted. I tried window.Owner() but it errors.

Probably something really simple or to do with MVVM Caliburn Micro app...Any ideas with the code on how to fix?

ChrisR
  • 81
  • 9
  • You're creating a new window and showing it every time that code runs. If you only want to open it once, add a field in the view model for the window and only create it if it's null. Or, disable the button after the first time it's clicked so it can't open multiple windows. – Sean Beanland May 10 '18 at 15:57
  • So this would be something like an If statement as I only want it to open the window once? – ChrisR May 10 '18 at 16:23
  • Yes, something like that – Sean Beanland May 10 '18 at 16:27
  • `if(muhWindowIsOpen) return; OpenChildWindow(); muhWindowIsOpen = true;` –  May 10 '18 at 16:31

0 Answers0