예제 #1
0
        private void Begin()
        {
            Configuration.UserAgent = typeof(App).Assembly.GetName().Name + "/" +
                                      typeof(App).Assembly.GetName().Version.ToString() + " (https://github.com/Paszt/weather-frog)";
            Configuration.ApiKey = My.Settings.WeatherApiKey;
            notifyIcon           = new()
            {
                Icon        = Utilities.CreateIcon(16, 16, (ImageSource)FindResource("FrogHeadDrawingImage")),
                DataContext = Current,
                ContextMenu = (System.Windows.Controls.ContextMenu)FindResource("NotifyIconMenu"),
                TrayPopup   = new TaskbarBalloon(),
                //ToolTip = new Resources.TaskbarBalloon(),
            };
            // Add bindings to notifyicon
            MultiBinding toolTipMultiBinding = new()
            {
                StringFormat = "Weather Frog \n{0}° {1}\n{2}\nLast updated: {3}",
                Bindings     =
                {
                    new Binding("Forecast.CurrentWeather.Temp")
                    {
                        Source = this
                    },
                    new Binding("Forecast.CurrentWeather.Condition.Text")
                    {
                        Source = this
                    },
                    new Binding("Forecast.Location.DisplayName")
                    {
                        Source = this
                    },
                    new Binding(nameof(LastUpdatedTimeString))
                    {
                        Source = this
                    },
                }
            };

            BindingOperations.SetBinding(notifyIcon, TaskbarIcon.ToolTipTextProperty, toolTipMultiBinding);

            Locations = My.Settings.Locations;

            SystemEvents sysEvents = new();

            sysEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
            sysEvents.ResumedFromSuspension  += SystemEvents_ResumedFromSuspension;
            sysEvents.AboutToSuspend         += SystemEvents_AboutToSuspend;

            if (My.Settings.UpdateDesktop)
            {
                desktopWallpaper = DesktopWallpaper.FromSystemParameters();
            }

            updateWeatherTimer = new(e => UpdateWeather(), null, TimeSpan.Zero, UpdateWeatherInterval);
        }