using PDF_Master.CustomControl; using PDF_Master.Helper; using PDF_Master.ViewModels; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; 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; namespace PDF_Master.Views { public class PromotionBanner { public string ImagePath { get; set; } public string Content { get; set; } public string Uri { get; set; } public PromotionBanner(string ImagePath,string Content,string uri) { this.ImagePath = ImagePath; this.Content = Content; this.Uri = uri; } } /// /// HomeContent.xaml 的交互逻辑 /// public partial class HomeContent : UserControl { private bool IsContextMenuOpen = false; public HomeContent() { InitializeComponent(); BtnGuid.IsChecked = true; } private void ToggleBtnSelect_Click(object sender, RoutedEventArgs e) { BtnGuid.IsChecked = false; BtnTool.IsChecked = false; BtnCloud.IsChecked = false; var btn = sender as CustomIconToggleBtn; if(btn != null ) { btn.IsChecked = true; } } private void BtnCreatPDF_Initialized(object sender, EventArgs e) { var btn = sender as Button; if(btn!=null) { btn.ContextMenu = null; } } private void BtnExpand_Click(object sender, RoutedEventArgs e) { ContextCreatePDF.PlacementTarget = BtnCreatPDF; ContextCreatePDF.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom; IsContextMenuOpen = !IsContextMenuOpen; ContextCreatePDF.IsOpen = IsContextMenuOpen; } private void ContextCreatePDF_Closed(object sender, RoutedEventArgs e) { var visual = VisualTreeHelper.HitTest(BtnExpand, Mouse.GetPosition(BtnExpand)); if (visual == null) { //点击其他地方引起的下拉框收取,猜需要更改按钮状态, //如果是点击按钮造成的下拉框收起,则不需要更改按钮状态(如果改了,会出现每次缓慢点击按钮都展开下拉框的现象) IsContextMenuOpen = false; } } private void UserControl_DragEnter(object sender, DragEventArgs e) { DragDropHelper.DragEnter(this,e); } private void UserControl_DragOver(object sender, DragEventArgs e) { DragDropHelper.DragOver(this, e); } private void UserControl_DragLeave(object sender, DragEventArgs e) { DragDropHelper.DragLeave(); } private void UserControl_Drop(object sender, DragEventArgs e) { try { DragDropHelper.Drop(this, e); string[] file = (string[])e.Data.GetData(DataFormats.FileDrop); if(file.Length>0) { (this.DataContext as HomeContentViewModel).AddFileFromDrag(file.ToList()); } } catch { } } } }