Handling close event when clicking on the top right cross button

7 posts, 0 answers
  1. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 13 May 2011 Link to this post

    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
  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 16 May 2011 Link to this post

    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
  3. DevCraft banner
  4. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 16 May 2011 Link to this post

    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
  5. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 16 May 2011 Link to this post

    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
  6. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 17 May 2011 Link to this post

    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
  7. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 17 May 2011 Link to this post

    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.
  8. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 19 May 2011 Link to this post

    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
Back to Top
DevCraft banner