123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using FWindSoft.WindowsApi;
- using System;
- using System.Collections.Generic;
- 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.Interop;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace FWindSoft.Wpf
- {
- /// <summary>
- /// WinMessageTip.xaml 的交互逻辑
- /// </summary>
- public partial class WinMessageTip : System.Windows.Window
- {
- public WinMessageTip(List<TipButtonItem> items)
- {
- InitializeComponent();
- this.DisableUseClose = true;
- this.ShowInTaskbar = false;
- this.AddHandler(Button.ClickEvent, new RoutedEventHandler(Button_Click));
- items.ForEach(item => StackButtons.Children.Add(CreateButton(item)));
- this.Loaded += WinMessageTip_Loaded;
- this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (s,e)=> {
- Clipboard.SetDataObject(Message, false);
- }));
- }
- private void WinMessageTip_Loaded(object sender, RoutedEventArgs e)
- {
- if(DisableUseClose)
- {
- DisableClose();
- }
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- Button button = e.Source as Button;
- if (button == null)
- return;
- TipButtonItem tipItem = button.Tag as TipButtonItem;
- try
- {
- if (tipItem == null)
- {
- Flag = 0;
- }
- else
- {
- Flag = Convert.ToInt32(tipItem.Flag);
- }
- }
- catch (Exception)
- {
- Flag = 0;
- }
- this.DialogResult = true;
- }
-
- internal bool DisableUseClose { get; set; }
- /// <summary>
- /// 选中标志
- /// </summary>
- public int Flag { get; private set; }
- public string Message {
- get { return TxtMessage.Text; }
- set { this.TxtMessage.Text = value;
- }
- }
- private Button CreateButton(TipButtonItem item)
- {
- Button button = new Button();
- button.MinWidth = 60;
- button.MinHeight = 23;
- button.Margin = new Thickness(10, 0, 10, 0);
- button.VerticalAlignment = VerticalAlignment.Center;
- button.Content = item.Content;
- button.IsDefault = item.IsDefault;
- button.IsCancel = item.IsCancel;
- if (item.ContentTemplate != null)
- {
- button.ContentTemplate = item.ContentTemplate;
- }
- button.Tag = item;
- return button;
- }
- private void DisableClose()
- {
- this.Closing += WinMessageTip_Closing;
- var interop = new WindowInteropHelper(this);
- int handle = interop.EnsureHandle().ToInt32();
- CloseButton.Disable(handle);
- }
- private void WinMessageTip_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- //当关闭按钮不能用,并且dialogResult不是ture时,定义为atl+F4,关闭,这种关闭方式取消
- if (DisableUseClose&&this.DialogResult!=true)
- {
- e.Cancel = true;
- }
- }
- }
- }
|