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

Prevent content from being clicked?

8 Answers 712 Views
DesktopAlert
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 23 Sep 2016, 08:17 PM
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)

8 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 26 Sep 2016, 08:11 AM
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.
0
Alex
Top achievements
Rank 1
answered on 26 Sep 2016, 02:19 PM
[quote]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.
[/quote]

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.
0
Nasko
Telerik team
answered on 27 Sep 2016, 06:12 AM
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.
0
Alex
Top achievements
Rank 1
answered on 27 Sep 2016, 01:48 PM
[quote]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.
[/quote]

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?
0
Nasko
Telerik team
answered on 28 Sep 2016, 08:25 AM
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.
0
Alex
Top achievements
Rank 1
answered on 30 Sep 2016, 08:15 PM
[quote]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.
[/quote]

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.
0
Alex
Top achievements
Rank 1
answered on 30 Sep 2016, 08:17 PM
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.
0
Nasko
Telerik team
answered on 03 Oct 2016, 08:18 AM
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.
Tags
DesktopAlert
Asked by
Alex
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Alex
Top achievements
Rank 1
Share this question
or