private void CreateStatusBarIcon()
        {
            var grip = (Control)FindControl(Application.Current.MainWindow, o => (o as Control)?.Name == "ResizeGripControl");

            var statusbar = (DockPanel)VisualTreeHelper.GetParent(grip);

            List <ChartConfig> chartConfigs = CreateChartConfigs();

            chart                       = new DonutChart();
            chart.Name                  = "TimeTrackerStatusBarChart";
            chart.Padding               = new Thickness(0, 2.5, 0, 1);
            chart.Stroke                = new SolidColorBrush(Color.FromRgb(40, 40, 40));
            chart.StrokeThickness       = 1;
            chart.InnerRadiusPercentage = 0.4;
            chart.MinWidth              = chart.MinHeight = statusbar.ActualHeight;
            chart.MaxWidth              = chart.MaxHeight = statusbar.ActualHeight;
            chart.Width                 = chart.Height = statusbar.ActualHeight;
            chart.SnapsToDevicePixels   = true;

            chart.Series = CreateChartSeries(chartConfigs);
            UpdateChartColors(chartConfigs);
            UpdateChartValues(chartConfigs);

            DockPanel.SetDock(chart, Dock.Right);
            statusbar.Children.Insert(1, chart);

            var timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(5);
            timer.Tick    += (s, a) =>
            {
                VSStateTimes times = UpdateChartValues(chartConfigs);

                long total = (times?.ElapsedMs.Sum(e => e.Value) ?? 0) / 1000;
                total = Math.Min(Math.Max(total / 30, 3), 60 * 5);

                timer.Interval = TimeSpan.FromSeconds(total);
            };
            timer.Start();

            timers.Add(timer);

            //Debug.WriteLine("*************");
            //DebugElement(statusbar, "");
            //Debug.WriteLine("*************");
            //DebugElement(Application.Current.MainWindow, "");
        }
        private VSStateTimes UpdateChartValues(List <ChartConfig> chartConfigs)
        {
            if (sm == null)
            {
                return(null);
            }

            VSStateTimes times = sm.ElapsedTimes;

            double[] values = chartConfigs.OrderBy(c => c.Pos)
                              .Select(config => (double)config.States.Sum(s => times.ElapsedMs[s]))
                              .ToArray();

            if (values.All(v => v <= 0))
            {
                values[chartConfigs.FindIndex(c => c.States.Contains(States.NoFocus))] = 1;
            }

            chart.UpdateValues(values);

            return(times);
        }