/// <summary> /// 初始化壁纸上显示的按钮状态 /// </summary> /// <param name="imgInfo"></param> private void InitBtnState(ImgInfo imgInfo) { if (imgInfo == null) { return; } btnPanel.Tag = imgInfo; btn_love.Foreground = Brushes.White; btn_wallpaper.Foreground = Brushes.White; btn_dislike.Foreground = Brushes.White; btn_down.Foreground = Brushes.White; btnPanel.Visibility = Visibility.Visible; Love love = UserDataManage.GetLove(imgInfo.Id); if (love != null) { if (love.Type == 1) { btn_love.Foreground = Brushes.Red; } else if (love.Type == -1) { btn_dislike.Foreground = Brushes.Red; } } Download down = UserDataManage.GetDown(imgInfo.Id); string fullName = System.IO.Path.Combine(this.DownPath, imgInfo.GetFileName()); if (System.IO.File.Exists(fullName)) { btn_down.Foreground = Brushes.Red; UserDataManage.SetDown(fullName, imgInfo); } }
/// <summary> /// 壁纸上动态显示的按钮点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn == null) { return; } ImgInfo imgInfo; if ((btn.Parent as StackPanel).Tag is ImgInfo info) { imgInfo = info; } else { imgInfo = this.GetimgInfo((btn.Parent as StackPanel).Tag); } switch (btn.Name) { case "btn_down": { if (btn.Foreground == Brushes.White) { btn.IsEnabled = false; string imgFullName = System.IO.Path.Combine(this.DownPath, imgInfo.GetFileName()); if (!System.IO.File.Exists(imgFullName)) { System.Drawing.Image img = WebHelper.GetImage(imgInfo.url); img.Save(imgFullName); img.Dispose(); } btn.Foreground = Brushes.Red; btn.IsEnabled = true; Growl.Success("下载成功。"); UserDataManage.SetDown(imgFullName, imgInfo); if (btn_love.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Love, imgInfo); btn_love.Foreground = Brushes.Red; btn_dislike.Foreground = Brushes.White; } } } break; case "btn_wallpaper": { if (btn.Foreground == Brushes.White) { btn.IsEnabled = false; string imgFullName = System.IO.Path.Combine(this.CachePath, imgInfo.GetFileName()); if (!System.IO.File.Exists(imgFullName)) { System.Drawing.Image img = WebHelper.GetImage(imgInfo.url); img.Save(imgFullName); img.Dispose(); } if (System.IO.File.Exists(imgFullName)) { WinApi.SetWallpaper(imgFullName); btn.Foreground = Brushes.Red; Growl.Success("壁纸设置成功。"); btn.IsEnabled = true; UserDataManage.AddRecord(RecordType.ManualWallpaper, imgInfo); } else { Growl.Error("未找到壁纸文件,壁纸设置失败。"); } } } break; case "btn_love": { if (btn.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Love, imgInfo); btn.Foreground = Brushes.Red; btn_dislike.Foreground = Brushes.White; } } break; case "btn_dislike": { if (btn.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Dislike, imgInfo); btn.Foreground = Brushes.Red; btn_love.Foreground = Brushes.White; } } break; } }
private void Btn_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn == null) { return; } ImgInfo imgInfo = (btn.Parent as StackPanel).Tag as ImgInfo; switch (btn.Name) { case "btn_down": { if (btn.Foreground == Brushes.White) { string imgFullName = System.IO.Path.Combine(this.DownPath, imgInfo.GetFileName()); if (!System.IO.File.Exists(imgFullName)) { System.Drawing.Image img = WebHelper.GetImage(imgInfo.url); img.Save(imgFullName); img.Dispose(); } btn.Foreground = Brushes.Red; UserDataManage.SetDown(imgFullName, imgInfo); Growl.Success("下载成功。"); if (btn_love.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Love, imgInfo); btn_love.Foreground = Brushes.Red; btn_dislike.Foreground = Brushes.White; } } } break; case "btn_wallpaper": { if (btn.Foreground == Brushes.White) { string imgFullName = System.IO.Path.Combine(this.CachePath, imgInfo.GetFileName()); if (!System.IO.File.Exists(imgFullName)) { System.Drawing.Image img = WebHelper.GetImage(imgInfo.url); img.Save(imgFullName); img.Dispose(); } WinApi.SetWallpaper(imgFullName); btn.Foreground = Brushes.Red; Growl.Success("壁纸设置成功。"); UserDataManage.AddRecord(RecordType.ManualWallpaper, imgInfo); } } break; case "btn_love": { if (btn.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Love, imgInfo); btn.Foreground = Brushes.Red; btn_dislike.Foreground = Brushes.White; } } break; case "btn_dislike": { if (btn.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Dislike, imgInfo); btn.Foreground = Brushes.Red; btn_love.Foreground = Brushes.White; this.EffectPicture(null, null); } } break; } }