⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frameworkelementactivationservice.cs

📁 wpf和cab的结合使用源码(转载)
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace Microsoft.Practices.CompositeUI.Windows.Activation
{
	/// <summary>
	/// An implementation of <see cref="IFrameworkElementActivationService"/>.
	/// </summary>
	public class FrameworkElementActivationService : IFrameworkElementActivationService
	{
		private WorkItem _workItem;

		/// <summary>
		/// The <see cref="WorkItem"/> where this service lives.
		/// </summary>
		[ServiceDependency]
		public WorkItem WorkItem
		{
			set
			{
				_workItem = value;
			}
		}

		public void FrameworkElementAdded(FrameworkElement frameworkElement)
		{
			frameworkElement.GotFocus += frameworkElement_GotFocus;
			frameworkElement.Unloaded += frameworkElement_Unloaded;
		}

		public void FrameworkElementRemoved(FrameworkElement frameworkElement)
		{
			frameworkElement.GotFocus -= frameworkElement_GotFocus;
			frameworkElement.Unloaded -= frameworkElement_Unloaded;
		}

		void frameworkElement_GotFocus(object sender, RoutedEventArgs e)
		{
			//don't deactivate if the user is just opening a menu (not sure this is correct in all cases)
			if (e.OriginalSource is MenuItem)
			{
				return;
			}

			if (_workItem != null)
			{
				e.Handled = true;
				_workItem.Activate();
			}
		}

		void frameworkElement_Unloaded(object sender, RoutedEventArgs e)
		{
			FrameworkElement frameworkElement = e.OriginalSource as FrameworkElement;
			frameworkElement.GotFocus -= frameworkElement_GotFocus;
			frameworkElement.Unloaded -= frameworkElement_Unloaded;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -