WPF MVVM Modeless Window how to stop opening multiple windows

242 views Asked by At

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?

0

There are 0 answers