This is a migrated thread and some comments may be shown as answers.

Handling close event when clicking on the top right cross button

6 Answers 113 Views
Window
This is a migrated thread and some comments may be shown as answers.
LE DREAU Steeve
Top achievements
Rank 1
LE DREAU Steeve asked on 13 May 2011, 10:38 AM
Hi,

I would like to be able to prevent clicking on the top right cross button to avoid closing the popup in certain conditions.
But in window, I have another button that can close the popup without testing this condition.
So I have tested using PreviewClosed event, but I can't know if I clicked on the top right cross button or if I have clicked on my button that have to close the popup.
Is there a way to do this please ?
Thanks

Steeve

6 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 16 May 2011, 10:55 AM
Hi Steeve,

Here is what you can do:
1. Raise a flag if you are going to close the Window via the button that you have added.
2. Change the template of the RadWindow and instead of the Close command use the Click event of the Close button. You can easily do this in Expression Blend. Just drop a RadWindow control on the design surface, right-click it and choose from the menu Edit Template-> Edit a Copy. Then, Blend will generate all the needed resources.

Hope this information helps.

Best wishes,
Konstantina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
LE DREAU Steeve
Top achievements
Rank 1
answered on 16 May 2011, 11:17 AM
Thanks for your answer but when I've changed the command, how can I handle it ?
I've made a class that inherits from radwindow to add custom behaviors, so I would like to handle the click event into it. Do you have a clue about that please ?
Thanks
0
LE DREAU Steeve
Top achievements
Rank 1
answered on 16 May 2011, 11:30 AM
here is what I've done :

I've changed the .Close command to .Click on the PART_Closebutton control into the template.
Into my class, i've written this code :

Private WithEvents _ButtonClose As Button
   Public Overrides Sub OnApplyTemplate()
       MyBase.OnApplyTemplate()
       _ButtonClose = Me.GetTemplateChild("PART_CloseButton")
   End Sub
   Private Sub ButtonCloseClicked() Handles _ButtonClose.Click
   End Sub

And I have the ButtonCloseClicked event fired.
But the popup is still closed by this button. How can I prevent the popup to be closed ?
Thanks
0
Konstantina
Telerik team
answered on 17 May 2011, 10:32 AM
Hello Steeve,

I had something else in mind, however since you started this way, all you need to do now is to set the Command property of the _ButtonClose to null:

     
   _ButtonClose.Command =
Nothing


Please let us know if that worked for you.

Regards,
Konstantina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
LE DREAU Steeve
Top achievements
Rank 1
answered on 17 May 2011, 11:24 AM
Hi,

Thanks for your answer but it doesn't work.
I've tried it into a simple project :

I've created a class like this :

Imports Telerik.Windows.Controls
  
Public Class MyPopup
    Inherits RadWindow
  
    Private _ButtonClose As Button
  
    Public Overrides Sub OnApplyTemplate()
        MyBase.OnApplyTemplate()
        _ButtonClose = Me.GetTemplateChild("PART_CloseButton")
        If _ButtonClose IsNot Nothing Then
            _ButtonClose.Command = Nothing
        End If
    End Sub
  
End Class

I open my popup and then click on the close button but the popup is still closed.
0
Miroslav Nedyalkov
Telerik team
answered on 19 May 2011, 05:31 PM
Hello Steeve,

I tried this code:
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
    Dim w As New MyWindow()
    w.Show()
End Sub
Private Class MyWindow
    Inherits RadWindow
    Public Overrides Sub OnApplyTemplate()
        MyBase.OnApplyTemplate()
        TryCast(Me.GetTemplateChild("PART_CloseButton"), RadButton).Command = New DelegateCommand(Function(o)
                                                                                                  End Function)
    End Sub
End Class

And it works fine. Could you please prepare us an example that demonstrates the issue and send us via support ticket?

Greetings,
Miroslav Nedyalkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Window
Asked by
LE DREAU Steeve
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
LE DREAU Steeve
Top achievements
Rank 1
Miroslav Nedyalkov
Telerik team
Share this question
or