timheuer / callisto

A control toolkit for Windows 8 XAML applications. Contains some UI controls to make it easier to create Windows UI style apps for the Windows Store in accordance with Windows UI guidelines.
http://timheuer.com/blog/archive/2012/05/31/introducing-callisto-a-xaml-toolkit-for-metro-apps.aspx
Other
338 stars 108 forks source link

Closing a CustomDialog via the back button overrides the IsOpen binding #244

Open mbruckner opened 10 years ago

mbruckner commented 10 years ago

My ViewModel shows/hides the CustomDialog using a boolean that is bound from xaml and a command to control it:

<controls:CustomDialog IsOpen="{Binding ChooserDialogVisible}"
BackButtonVisibility="Visible" BackButtonCommand="{Binding CancelDialogCommand}" >

However, once the dialog is closed using the back button, it's not possible to open it again using the ChooserDialogVisible boolean because the CustomDialog control sets the value to false in its default handler.

By looking into the source I was able to create a workaround by attaching an event handler that does nothing, but that feels like an ugly hack.

I suggest checking if there's a binding to IsOpen and if that's the case, skip setting IsOpen to false. This would be CustomDialog.cs:50 in the current dev branch:

if (BackButtonClicked != null) { BackButtonClicked(bbs, bba); } else if(GetBindingExpression(IsOpenProperty) == null) // check binding instead of simple else { IsOpen = false; }

mbruckner commented 10 years ago

Another option would be to introduce a new dependency property:

bool SetIsOpenOnDialogClose {get;set;}

Default should be true to maintain the current behavior of the dialog. Instead of checking whether a binding exists, SetIsOpenOnDialogClose would be checked. However, the problem with this approach is that in the current implementation, this value would be checked only if there isn't an event handler attached, so the property is not as self-describing as I'd like.

bartlannoeye commented 9 years ago

@mbruckner I ran in the same issue today and was looking at your workaround. But digging deeper into it, there isn't a bug in Callisto. To be able to reopen the CustomDialog, you simply need two way binding on IsOpen:

IsOpen="{Binding ChooserDialogVisible, Mode=TwoWay}" 

Edit: wrote a small post + sample solution for using the CustomDialog with MVVM: http://www.bartlannoeye.com/blog/custom-messagedialog-with-mvvm