DesktopAlert not visible/not show

2 posts, 0 answers
  1. Jan
    Jan avatar
    1 posts
    Member since:
    Oct 2016

    Posted 01 Nov Link to this post

    Hello,

    I'd like to use a DesktopAlert in a WPF MVVM app.

    I copy the code from the Telerik WPF app - DesktopAlert Examples - First Look app (email example).

    Code:

    public class AlertViewModel : BaseViewModel
    {
    private RadDesktopAlertManager desktopAlertManager;

    public AlertViewModel()
    {
    this.desktopAlertManager = new RadDesktopAlertManager(AlertScreenPosition.BottomRight, 5d);
    }

    public Action ActivateMainWindowAction { get; set; }
    private void OnAlertCommandExecuted(object param)
    {            
    if (this.ActivateMainWindowAction != null)
    {
    this.ActivateMainWindowAction.Invoke();
    }            
    }

    public void TestAlert()
    {
    BitmapImage b = new BitmapImage();
    b.BeginInit();
    b.UriSource = new Uri("C:\\...\\error.png");
    b.EndInit();

    this.desktopAlertManager.ShowAlert(new DesktopAlertParameters
    {
    Header = "Header",
    Content = "Content",
    Icon = new Image { Source = b, Width = 48, Height = 48 },
    IconColumnWidth = 48,
    IconMargin = new Thickness(10, 0, 20, 0),
    Command = new DelegateCommand(this.OnAlertCommandExecuted),
    CommandParameter = "ABC"
    });
    }
    }

    public partial class Alert : UserControl
    {
    public Alert()
    {
    InitializeComponent();
    AlertViewModel vm = ServiceLocator.Current.GetInstance<AlertViewModel>();
    vm.ActivateMainWindowAction = new Action(this.ActivateMainWindow);
    DataContext = vm;
    }

    private void ActivateMainWindow()
    {
    var mainWindow = Application.Current.MainWindow;

    if (mainWindow != null)
    {
    if (mainWindow.WindowState == WindowState.Minimized)
    {
    mainWindow.WindowState = WindowState.Normal;
    }

    if (!mainWindow.IsActive)
    {
    mainWindow.Activate();
    }
    }
    }
    }

     

    The DesktopAlertParameters command never execute and the alert never show.

    Is there something i miss? If i try desktop alert on a new classic WPF app (no mvvm) works withuot problems.

     

    Thanks.

     

  2. Nasko
    Admin
    Nasko avatar
    586 posts

    Posted 03 Nov Link to this post

    Hi Jan,

    In order to show the DesktopAlert the "TestAlert" method should be called. Please, check the attached sample that demonstrates how to show the DesktopAlert as expected.

    Hope this helps.

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