1

This error happen when I open new usercontrol into dialoghost during opening dialoghost : enter image description here

when I press submit button this is my code xaml:

MainWindow:

<Grid>

    <Button Content="Show"
            Command="{Binding OpenRegisCommand}"
            VerticalAlignment="Bottom"
            Margin="0 0 0 40"
            Foreground="White"
            Width="100"
            Background="#23A9F2">

    </Button>

    <md:DialogHost Identifier="RootDialogHostId">

    </md:DialogHost>

</Grid>

my usercontrol and my mainwindow using 1 viewmodel:

public MainViewModel()
        {
            OpenRegisCommand = new DelegateCommand(OpenFormRegis);
            Submit = new DelegateCommand(Check);
        }

        private async void Check()
        {
            if(Name.Equals("admin")&&Pass.Equals("123456"))
            {
                var view = new DialogOk();
                await DialogHost.Show(view, DialogHostId);
            }
            else
            {
                var view = new DialogNo();
                await DialogHost.Show(view, DialogHostId);
            }

        }

        private async void OpenFormRegis()
        {
            var view = new FormRegis();
            await DialogHost.Show(view, DialogHostId);
        }

button submit in my usercontrol binding to DelegateCommand Submit in my viewmodel

Nam Dang
  • 21
  • 6

2 Answers2

0

Each dialog hosts can be used to show one view at a time.

If you have two views that you wanted to shot at the same time (less likely), you will need two dialog hosts.

In your case, if you're trying to open the "OpenFormRegis" window in your dialog host, I would suggest you to use Windows instead.

JeeShen Lee
  • 3,476
  • 5
  • 39
  • 59
0

In my case, I did the following:

1- Get the dialogs that are active, using DialogHost.GetDialogSession("RootDialog").

2- If it is different from null, set the content with the UpdateContent(alertBox) method which updates the content of the dialog.

3- If it is null, establish the usual flow to show the content of the dialog.

  AlertBoxView alertBox = new AlertBoxView();
  alertBox.DataContext = this;

  var dialog = DialogHost.GetDialogSession(IdentifierDialog);

  if (dialog != null)
  {
      dialog.UpdateContent(alertBox);
  }
  else
  {
      await DialogHost.Show(alertBox, IdentifierDialog);
  }

*AlertBoxView: is my custom view of DialogHost

*IdentifierDialog: is the variable that takes the Identifier of the dialog

Kevino
  • 1