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

Can't keep reference to desktop alert

1 Answer 99 Views
DesktopAlert
This is a migrated thread and some comments may be shown as answers.
MartinM
Top achievements
Rank 1
MartinM asked on 28 Jul 2015, 07:45 PM

Using WinControls version 2014.3.1202.40

I am attempting to keep a list of all popups that have been displayed so far so I can programmatically close certain popups based on a condition, later. So after creating a list and adding a reference of a popup to it, the reference to it in the list disappears after calling .show() on the alert object.

A simple example:

 

var listOfPopups = new List<RadDesktopAlert>();
 
var alert = new RadDesktopAlert();
 
listOfPopups.Add(alert); // listOfPopups.Count == 1 now.
 
alert.Show(); // listOfPopups.Count == 0 now...

 

Is this by design? And if so, is there any other way to keep track of them, or get access to the popups through the desktopAlertManager?

 

Thanks,

 

 

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 29 Jul 2015, 01:29 PM
Hi Martin,

Thank you for writing. 

I tested your scenario with a list and a dictionary and I am able to access the already displayed alerts and hide them. Please check my example below: 
public partial class Form1 : Form
{
    private IDictionary<int, RadDesktopAlert> alerts;
 
    public Form1()
    {
        InitializeComponent();
        this.alerts = new Dictionary<int, RadDesktopAlert>();
    }
 
    private void btnAddAlert_Click(object sender, EventArgs e)
    {
        RadDesktopAlert alert = new RadDesktopAlert();
        alert.AutoClose = false;
        alert.CaptionText = "New Alert";
        alert.ContentText = "Some text";
        alert.Show();
 
        alerts[this.alerts.Count] = alert;
    }
 
    private void btnFindAlert_Click(object sender, EventArgs e)
    {
        int id;
        bool isInteger = int.TryParse(this.tbId.Text, out id);
        if (isInteger)
        {
             if (alerts.ContainsKey(id))
             {
                 alerts[id].Hide();
                 alerts.Remove(id);
             }
        }
    }
}

As to the DesktopAlertManager, it is basically responsible for setting the position of each alert when it is being created. Just before an alert is shown it gets registered by the alert manager and its coordinates are calculated depending on the screen settings and the other alerts which are already shown.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
DesktopAlert
Asked by
MartinM
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or