using DTS.Common.Base;
using DTS.Common.Events;
using DTS.Common.Interface;
using Prism.Ioc;
using Prism.Events;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace DTS.Viewer.PSDReport
{
///
/// Interaction logic for PSDReportMainViewGrid.xaml
///
public partial class PSDReportMainViewGrid : IPSDReportMainViewGrid
{
public PSDReportMainViewGrid()
{
InitializeComponent();
Loaded += PSDReportMainViewGrid_Loaded;
}
private IEventAggregator _eventAggregator { get; set; }
private void SetFocus()
{
chartResultsTab.IsSelected = true;
chartResultsTab.Focusable = true;
chartResultsTab.Focus();
}
//FB 14797 Subscribe to event after the page loaded to make sure eventAggregator is available
private void PSDReportMainViewGrid_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
_eventAggregator = ContainerLocator.Container.Resolve();
_eventAggregator?.GetEvent().Subscribe(OnGraphLoadedCountNotification);
}
//FB 14797 Set the focus to first tab (chartOptTab) after the graph is fully loaded (3 sec)
private void OnGraphLoadedCountNotification(GraphLoadedCountNotificationArg arg)
{
if (null != DataContext && (IBaseViewModel)DataContext != arg.ParentVM) return;
Task.Run(() =>
{
Thread.Sleep(TimeSpan.FromSeconds(3));
Dispatcher.BeginInvoke((Action)SetFocus);
});
}
}
}