ScreensaverWindow.xaml.cs
上传用户:liuqi822
上传日期:2022-03-21
资源大小:88k
文件大小:3k
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using TwitterClient;
- using System.Timers;
- using System.Globalization;
- namespace Screensaver1
- {
- /// <summary>
- /// Interaction logic for Window1.xaml
- /// </summary>
- public partial class ScreensaverWindow : Window
- {
- Point? lastMousePosition;
- public static readonly DependencyProperty ScreensaverContentProperty =
- DependencyProperty.Register("ScreensaverContent", typeof(object), typeof(ScreensaverWindow), new UIPropertyMetadata(string.Empty));
- TwitterService twitterService;
- public ScreensaverWindow()
- {
- InitializeComponent();
- this.DataContext = this;
- twitterService = new TwitterService(Properties.Settings.Default.TwitterHashcode);
- twitterService.FeedItemChanged += new EventHandler<FeedItemEventArgs>(twitterService_FeedItemChanged);
- twitterService.Start();
- }
- void twitterService_FeedItemChanged(object sender, FeedItemEventArgs e)
- {
- this.Dispatcher.Invoke(new Action(() => this.ScreensaverContent = new FeedItemControl(e.Item)));
- }
- public object ScreensaverContent
- {
- get { return GetValue(ScreensaverContentProperty); }
- set { SetValue(ScreensaverContentProperty, value); }
- }
- protected override void OnKeyDown(KeyEventArgs e)
- {
- Close();
- }
- protected override void OnMouseDown(MouseButtonEventArgs e)
- {
- Close();
- }
- protected override void OnMouseMove(MouseEventArgs e)
- {
- Point currentMousePosition = e.MouseDevice.GetPosition(this);
- if (lastMousePosition.HasValue)
- {
- // Check if the mouse position has changed
- if (Math.Abs(lastMousePosition.Value.X - currentMousePosition.X) > 0 ||
- Math.Abs(lastMousePosition.Value.Y - currentMousePosition.Y) > 0)
- {
- Close();
- }
- }
- else
- {
- lastMousePosition = currentMousePosition;
- }
- }
- }
- }