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.