Prevent content from being clicked?

9 posts, 0 answers
  1. Alex
    Alex avatar
    16 posts
    Member since:
    Nov 2013

    Posted 23 Sep Link to this post

    I'm trying to override or remove the ability to click directly on the content of a DesktopAlert. My problem is that when you set the alert's content to a plain string, it acts as a link-button and upon clicking the text, it will close the window. This is a problem since there are certain DesktopAlerts that I don't want to be closed at all. I can set it as Enabled = False but then the dropdown menu and other parts of the alert quit functioning. This is all created from code behind so it is a little harder for me to set any properties or templates for it in XAML.

    Dim mainAlert = New RadDesktopAlert() With {
        .Header = "Messages",
        .Content = "You have " & unreadCount & " new messages",
        .Height = 75,
        .Width = 300,
        .IconTemplate = TryCast(Application.Current.FindResource("radIconTemplate"), DataTemplate),
        .IconColumnWidth = 30,
        .IconMargin = New Thickness(5, 10, 15, 0),
        .CanAutoClose = False,
        .ShowCloseButton = False,
        .Tag = "main",
        .ShowMenuButton = True,
        .MenuItemsSource = GetDesktopAlertMenuItems
    }
    manager.ShowAlert(mainAlert)
  2. Nasko
    Admin
    Nasko avatar
    588 posts

    Posted 26 Sep Link to this post

    Hello Alex,

    In order to prevent closing of RadDesktopAlert when its content gets pressed you need to handle the PreviewMouseLeftButtonUp event. Inside it you need to check if the UI Element that has been clicked in not the Close Button and if so to handle the event:
    Private Sub OnAlertPreviewMouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs)
            If e.OriginalSource.GetType() IsNot GetType(RadButton) Then
                e.Handled = True
            End If
    End Sub

    Hope this helps.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Alex
    Alex avatar
    16 posts
    Member since:
    Nov 2013

    Posted 26 Sep in reply to Nasko Link to this post

    Nasko said:Hello Alex,

    In order to prevent closing of RadDesktopAlert when its content gets pressed you need to handle the PreviewMouseLeftButtonUp event. Inside it you need to check if the UI Element that has been clicked in not the Close Button and if so to handle the event:
    Private Sub OnAlertPreviewMouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs)
            If e.OriginalSource.GetType() IsNot GetType(RadButton) Then
                e.Handled = True
            End If
    End Sub

    Hope this helps.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.


    Could you possibly elaborate on how to make this event handled from code-behind? I tried to add something along the lines of  AddHandler mainAlert.OnAlertPreviewMouseLeftButtonUp, AddressOf cmdContent_Click  but OnAlertPreviewMouseLeftButtonUp doesn't exist in that context, only .Click does (which didn't actually do what I wanted). I need to add the event handler to that raddesktopalert when it is created in code behind. If it was in XAML adding what you posted would be easy.

    Thanks for the help.
  5. Nasko
    Admin
    Nasko avatar
    588 posts

    Posted 27 Sep Link to this post

    Hi Alex,

    Please, check the attached sample project that demonstrates the described in my previous response approach and how to handle the PreviewMouseLeftButtonUp event.

    I hope this will help you.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Alex
    Alex avatar
    16 posts
    Member since:
    Nov 2013

    Posted 27 Sep in reply to Nasko Link to this post

    Nasko said:Hi Alex,

    Please, check the attached sample project that demonstrates the described in my previous response approach and how to handle the PreviewMouseLeftButtonUp event.

    I hope this will help you.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.


    Thanks, that did the trick. I swear I had that typed in at one point and it wouldn't work, or maybe I'm crazy.

    Is there any way to remove the underline that shows up when you hover the content text without replacing the entire style?
  7. Nasko
    Admin
    Nasko avatar
    588 posts

    Posted 28 Sep Link to this post

    Hello Alex,

    You could achieve the desired appearance by creating a ContentTemplate with a TextBlock with set IsHitTestVisible to False - thus the underlying won't be visible.

    Check the attached sample that demonstrates that approach.

    Hope this helps.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  8. Alex
    Alex avatar
    16 posts
    Member since:
    Nov 2013

    Posted 30 Sep in reply to Nasko Link to this post

    Nasko said:Hello Alex,

    You could achieve the desired appearance by creating a ContentTemplate with a TextBlock with set IsHitTestVisible to False - thus the underlying won't be visible.

    Check the attached sample that demonstrates that approach.

    Hope this helps.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.


    Thank you much, that did the trick. So far I've been able to do almost everything I need. 

    I hate to lean on you so much, but I have a couple more scenarios I'm curious about

    1) Is there any functionality I'm missing to be able to insert a DesktopAlert into a DesktopAlertManager at a certain position?
     and
    2) If I have 3 alerts open, and wish to change the content of the center (or 2nd) alert, but it's height changes, is there any way to make the DesktopAlertManager recalculate/reanimate the collection to adapt for the change? Right now if I change an alert's height it just kinda overlaps it's surrounding alerts.

    What I'm doing is opening a "main" alert that is permanently open, and then having "notification" alerts that stack on top of that. The notifications have a ~10 second delay then fall off. On occassion, someone will click one of the notification alerts to view more info about it, and it may change in size to accommodate that info.
  9. Alex
    Alex avatar
    16 posts
    Member since:
    Nov 2013

    Posted 30 Sep in reply to Alex Link to this post

    Sorry I wasn't super clear about scenario #1 in my post above... What I mean to ask is if there was any way to insert an alert into RadDesktopManager's collection at a certain position, such as inserting the alert at index 0 so its appears at the bottom, or inserting it at index 2 so it appears in-between two other alerts.
  10. Nasko
    Admin
    Nasko avatar
    588 posts

    Posted 03 Oct Link to this post

    Hi Alex,

    With the current implementation of RadDesktopAlert and RadDesktopAlertManager both placing an alert at a specific position and recalculation of the current Alerts Height when content get changed is not supported out of the box. Unfortunately, there isn't an approach that we could suggest you in order to achieve that desired behavior and functionality.

    Hope the provided information will be helpful for you. If you have any additional questions or concerns regarding Telerik controls, please do not hesitate to contact us.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready