Drise
Drise

Reputation: 4388

materialDesign:DialogHost dialog closes when trying to open file from FileOpenDialog

I have a control within a <materialDesign:DialogHost CloseOnClickAway="True" /> that opens a system FileOpenDialog. If I double click in the FileOpenDialog to open a file, the background dialog in the host closes. I've narrowed it down that the file dialog closes on the second mouse-down and the application responds to the subsequent mouse-up event.

Any suggestions on how to prevent this?

Upvotes: 0

Views: 1088

Answers (1)

Drise
Drise

Reputation: 4388

So I came up with a solution albeit it feels a little hackish. The <materialDesign:DialogHost /> has a property DialogClosing that allows you to specify a callback as the closing event is fired. In the code-behind, I created an event handler public void MainViewModel_CheckIfDialogShouldClose(object sender, DialogClosingEventArgs e) that calls a subclassed FileOpenDialog's WasOpenRecently function. This function returns true/false if the dialog was closed within the last 250 milliseconds. If we get true back, we e.Cancel(); to cancel the DialogHost's closing event.

Upvotes: 1

Related Questions