• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# WeakEventListener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中WeakEventListener的典型用法代码示例。如果您正苦于以下问题:C# WeakEventListener类的具体用法?C# WeakEventListener怎么用?C# WeakEventListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WeakEventListener类属于命名空间,在下文中一共展示了WeakEventListener类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AfterListenerIsNull_EventDetaching

        public void AfterListenerIsNull_EventDetaching()
        {
            WasDetached = false;
            EventCounter = 0;

            var list = new ObservableCollection<int>();

            WeakEventListener<object, ObservableCollection<int>, EventArgs> weakEventListener = null;

            var obj = new object();

            weakEventListener = new WeakEventListener<object, ObservableCollection<int>, EventArgs>(obj, list);

            list.CollectionChanged += weakEventListener.OnEvent;
            weakEventListener.OnEventAction += (o, o1, arg3) =>
                {
                    EventCounter++;
                };
            weakEventListener.OnDetachAction += (listener, source) =>
                {
                    source.CollectionChanged -= listener.OnEvent;
                    WasDetached = true;
                };

            list.Add(1);
            obj = null;
            GC.Collect();

            list.Add(2);
            GC.Collect();

            Assert.IsTrue(WasDetached);
            Assert.AreEqual(EventCounter, 1);
        }
开发者ID:mparsin,项目名称:Elements,代码行数:34,代码来源:WeakEventListenerTests.cs


示例2: SpreadsheetCellDataFieldViewModel

        public SpreadsheetCellDataFieldViewModel(Type viewModelType, PropertyInfo propertyInfo, IEditableProxy model, DetailsViewModel parentViewModel, IColumnItem column)
        {            
            _propertyInfo = propertyInfo;            
            _parentModel = model;
            if (_parentModel != null)
            {                
                var parentModelBO = _parentModel as BusinessBase;
                if (parentModelBO != null)
                {
                    var weakListener = new WeakEventListener<SpreadsheetCellDataFieldViewModel, BusinessBase, PropertyChangedEventArgs>(this, parentModelBO);

                    parentModelBO.PropertyChanged += weakListener.OnEvent;
                    weakListener.OnEventAction += OnParentModelPropertyChanged;
                    weakListener.OnDetachAction += Static;
                }

                _allProperties = _parentModel.GetAllPropertiesForInstance();
                var root = _parentModel.GetModel();
                if (root != null)
                    _allMasterProperties = root.GetAllPropertiesForInstance();                
            }

            _parentDetailsVM = parentViewModel;
            _fieldViewModelType = viewModelType;
            _column = column;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:26,代码来源:SpreadsheetCellDataFieldViewModel.cs


示例3: Initialize

        public virtual void Initialize(ChecklistSingleViewModel parentVM, IFieldDefinitionEntity fieldDef, IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;

            _process = (TemplateEntity)parentVM.QuestionsTemplate;
            _parentVM = parentVM;
            _fieldDefinition = fieldDef;
            ChangeChartTypeCommand = new DelegateCommand(ExecuteChange);

            PrepareFieldDefRelatedData();

            var weakListener = new WeakEventListener<SPCChartControlViewModel, ChecklistViewModelBase, EventArgs>(this, parentVM);
            parentVM.SelectesQuestionChanged += weakListener.OnEvent;
            weakListener.OnEventAction = OnSelectedQuestionChanged;
            weakListener.OnDetachAction = (listener, source) =>
            {
                source.SelectesQuestionChanged -= listener.OnEvent;
            };

            ShowLCLAnyChart = true; ShowUCLAnyChart = true; ShowMeanAnyChart = true;
            ShowLCLRangeChart = true; ShowUCLRangeChart = true; ShowMeanRangeChart = true;
            ShowUSL = false; ShowLSL = false;

            OnSelectedQuestionChanged(this, parentVM, EventArgs.Empty);            
        }
开发者ID:mparsin,项目名称:Elements,代码行数:25,代码来源:SPCChartControlViewModel.cs


示例4: AttachObservableModelCallback

		private static void AttachObservableModelCallback(DependencyObject source, DependencyPropertyChangedEventArgs args)
		{
			var typeName = args.NewValue as string;
			var view = source as FrameworkElement;
			if (typeName == null || view == null)
				return;

			var modelType = Type.GetType("Raven.Studio.Models." + typeName) ?? Type.GetType(typeName);
			if (modelType == null)
				return;

			try
			{
				var model = (Model)Activator.CreateInstance(modelType);
				model.ForceTimerTicked();

				var observable = (IObservable)Activator.CreateInstance(typeof(Observable<>).MakeGenericType(modelType));
				observable.Value = model;
				view.DataContext = observable;

				SetPageTitle(model, view);
				
				var weakListener = new WeakEventListener<IObservable, object, RoutedEventArgs>(observable);
				view.Loaded += weakListener.OnEvent;
				weakListener.OnEventAction = OnViewLoaded;
				weakListener.OnDetachAction = listener => view.Loaded -= listener.OnEvent;
			}
			catch (Exception ex)
			{
				throw new InvalidOperationException(string.Format("Cannot create instance of model type: {0}", modelType), ex);
			}
		}
开发者ID:neiz,项目名称:ravendb,代码行数:32,代码来源:ModelAttacher.cs


示例5: Handler

        private void Handler()
        {
            var propertyChangedListener = new WeakEventListener<PopUpSearchView, ListBox, SelectionChangedEventArgs>(this, ListBoxItems);

            ListBoxItems.SelectionChanged += propertyChangedListener.OnEvent;
            propertyChangedListener.OnEventAction += ValuePropertyChanged;
            propertyChangedListener.OnDetachAction += Static;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:8,代码来源:PopUpSearchView.xaml.cs


示例6: SelectCrossRefViewModel

        /// <summary>
        /// Initializes a new instance of the <see cref="SelectCrossRefViewModel"/> class.
        /// </summary>
        public SelectCrossRefViewModel()
        {
            CloseOnReturn = false;

            var weakListener = new WeakEventListener<SelectCrossRefViewModel, ObservableCollection<object>, NotifyCollectionChangedEventArgs>(this, _selectedItems);
            _selectedItems.CollectionChanged += weakListener.OnEvent;
            weakListener.OnEventAction += SelectedItemsOnCollectionChanged;
            weakListener.OnDetachAction += Static;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:12,代码来源:SelectCrossRefViewModel.cs


示例7: SearchListView

        public SearchListView()
        {
            InitializeComponent();

            var dataContextChangedListener = 
                new WeakEventListener<SearchListView, SearchListView, DependencyPropertyChangedEventArgs>(this, this);
            DataContextChanged += dataContextChangedListener.OnEvent;
            dataContextChangedListener.OnEventAction = OnDataContextChanged;
            dataContextChangedListener.OnDetachAction = OnDetachDataContextChanged;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:10,代码来源:SearchListView.xaml.cs


示例8: WeakCollectionChangedWrapper

 public WeakCollectionChangedWrapper( IList sourceList )
 {
     _innerList = sourceList;
       var notifyList = _innerList as INotifyCollectionChanged;
       if( notifyList != null )
       {
     _innerListListener = new WeakEventListener<NotifyCollectionChangedEventArgs>( OnInnerCollectionChanged );
     CollectionChangedEventManager.AddListener( notifyList, _innerListListener );
       }
 }
开发者ID:eolandezhang,项目名称:Diagram,代码行数:10,代码来源:WeakCollectionChangedWrapper.cs


示例9: NetworkConnectionStateTrigger

		/// <summary>
		/// Initializes a new instance of the <see cref="NetworkConnectionStateTrigger"/> class.
		/// </summary>
		public NetworkConnectionStateTrigger()
		{
			var weakEvent =
				new WeakEventListener<NetworkConnectionStateTrigger, object>(this)
				{
					OnEventAction = (instance, source) => NetworkInformation_NetworkStatusChanged(source),
					OnDetachAction = (instance, weakEventListener) => NetworkInformation.NetworkStatusChanged -= weakEventListener.OnEvent
				};
			NetworkInformation.NetworkStatusChanged += weakEvent.OnEvent;
			UpdateState();
		}
开发者ID:b3540,项目名称:WindowsStateTriggers,代码行数:14,代码来源:NetworkConnectionStateTrigger.cs


示例10: ResolveDatabaseObjectsViewModel

        public ResolveDatabaseObjectsViewModel()
        {
            DatabaseObjectList = new ObservableCollection<DatabaseObject>();

            var weakEventListener = new WeakEventListener<object, ObservableCollection<DatabaseObject>, EventArgs>(this, DatabaseObjectList);

            DatabaseObjectList.CollectionChanged += weakEventListener.OnEvent;
            weakEventListener.OnEventAction += RaiseChanges;

            weakEventListener.OnDetachAction += Static;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:11,代码来源:ResolveDatabaseObjectsViewModel.cs


示例11: DiagramView

        public DiagramView()
        {
            InitializeComponent();
            KeyDown += DiagramPanel_KeyDown;

            var weakListener = new WeakEventListener<DiagramView, DiagramView, RoutedEventArgs>(this, this);

            this.Loaded += weakListener.OnEvent;
            weakListener.OnEventAction += OnDiagramViewLoaded;
            weakListener.OnDetachAction += Static;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:11,代码来源:DiagramView.xaml.cs


示例12: HandleWeakEvent

        public void HandleWeakEvent()
        {
            Dummy dummy = new Dummy();
            bool weakEventReceived = false;
            var listener = new WeakEventListener<PropertyChangedEventArgs>((sender, eventArgs) => weakEventReceived = true);

            PropertyChangedEventManager.AddListener(dummy, listener, String.Empty);
            dummy.RaisePropertyChanged();
            Assert.IsTrue(weakEventReceived);
            weakEventReceived = false;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:11,代码来源:WeakEventListenerTest.cs


示例13: AddEventHandlers

        /// <summary>
        /// Adds the event handlers.
        /// </summary>
        private void AddEventHandlers()
        {
            var propertyChangedListener = new WeakEventListener<BusinessObjectIsValidListener, BusinessBase, PropertyChangedEventArgs>(this, Model);
            Model.PropertyChanged += propertyChangedListener.OnEvent;
            propertyChangedListener.OnEventAction = OnModelPropertyChanged;
            propertyChangedListener.OnDetachAction = Static;

            var childChangedListener = new WeakEventListener<BusinessObjectIsValidListener, BusinessBase, ChildChangedEventArgs>(this, Model);
            Model.ChildChanged += childChangedListener.OnEvent;
            childChangedListener.OnEventAction = OnModelChildChanged;
            childChangedListener.OnDetachAction = Static;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:15,代码来源:BusinessObjectIsValidListener.cs


示例14: ServiceTypeInfo

        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceTypeInfo"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        public ServiceTypeInfo(ServiceExposedTypeEdit type)
        {
            _nameExpression = () => type.Name;
            _guidExpression = () => type.Guid;

            var propertyChangedListener =
                new WeakEventListener<ServiceTypeInfo, ServiceExposedTypeEdit, PropertyChangedEventArgs>(this, type);

            type.PropertyChanged += propertyChangedListener.OnEvent;
            propertyChangedListener.OnEventAction += OnTypePropertyChanged;
            propertyChangedListener.OnDetachAction += Static;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:16,代码来源:ServiceTypeInfo.cs


示例15: TableDefinition

        /// <summary>
        /// Initializes a new instance of the <see cref="TableDefinition" /> class.
        /// </summary>
        public TableDefinition()
        {
            FieldList = new List<TableFieldDefinition>();

            var relationships = new ObservableCollection<TableRelationshipDefinition>();
            Relationships = relationships;

            var weakListenerKeyDown = new WeakEventListener<TableDefinition, ObservableCollection<TableRelationshipDefinition>, NotifyCollectionChangedEventArgs>(this, relationships);
            relationships.CollectionChanged += weakListenerKeyDown.OnEvent;
            weakListenerKeyDown.OnEventAction += RelationshipsCollectionChanged;
            weakListenerKeyDown.OnDetachAction += Static;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:15,代码来源:TableDefinition.cs


示例16: ShouldStoreEventHandler

        public void ShouldStoreEventHandler()
        {
            bool weakEventReceived = false;

            var listener = new WeakEventListener<PropertyChangedEventArgs>((sender, eventArgs) => weakEventReceived = true);

            // Check whether EventHandler was stored correctly.
            Assert.IsNotNull(listener.EventHandler);
            listener.EventHandler(null, null);
            Assert.IsTrue(weakEventReceived);
            weakEventReceived = false;
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:12,代码来源:WeakEventListenerTest.cs


示例17: OnDataContextChanged

        private static void OnDataContextChanged(SearchListView view, object sender, DependencyPropertyChangedEventArgs args)
        {
            var dc = args.NewValue as SearchListViewModel;
            if (dc == null)
                return;

            var selectedChangedListener = 
                new WeakEventListener<SearchListView, SearchListViewModel, SelectedChangedEventArgs>(view, dc);
            dc.SelectedChanged += selectedChangedListener.OnEvent;
            selectedChangedListener.OnEventAction = OnSelectedChanged;
            selectedChangedListener.OnDetachAction = OnDetachSelectedChanged;
        }
开发者ID:mparsin,项目名称:Elements,代码行数:12,代码来源:SearchListView.xaml.cs


示例18: OnValuePropertyChanged

		private static void OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			var obj = (IsNullOrEmptyStateTrigger)d;
			var val = e.NewValue;

			obj.IsActive = IsNullOrEmpty(val);

			if (val == null)
				return;

			// Try to listen for various notification events
			// Starting with INorifyCollectionChanged
			var valNotifyCollection = val as INotifyCollectionChanged;
			if (valNotifyCollection != null)
			{
				var weakEvent = new WeakEventListener<INotifyCollectionChanged, object, NotifyCollectionChangedEventArgs>(valNotifyCollection)
				{
					OnEventAction = (instance, source, args) => obj.IsActive = IsNullOrEmpty(instance),
					OnDetachAction = (instance, weakEventListener) => instance.CollectionChanged -= weakEventListener.OnEvent
				};

				valNotifyCollection.CollectionChanged += weakEvent.OnEvent;
				return;
			}

			// Not INotifyCollectionChanged, try IObservableVector
			var valObservableVector = val as IObservableVector<object>;
			if (valObservableVector != null)
			{
				var weakEvent = new WeakEventListener<IObservableVector<object>, object, IVectorChangedEventArgs>(valObservableVector)
				{
					OnEventAction = (instance, source, args) => obj.IsActive = IsNullOrEmpty(instance),
					OnDetachAction = (instance, weakEventListener) => instance.VectorChanged -= weakEventListener.OnEvent
				};

				valObservableVector.VectorChanged += weakEvent.OnEvent;
				return;
			}

			// Not INotifyCollectionChanged, try IObservableMap
			var valObservableMap = val as IObservableMap<object,object>;
			if (valObservableMap != null)
			{
				var weakEvent = new WeakEventListener<IObservableMap<object, object>, object, IMapChangedEventArgs<object>>(valObservableMap)
				{
					OnEventAction = (instance, source, args) => obj.IsActive = IsNullOrEmpty(instance),
					OnDetachAction = (instance, weakEventListener) => instance.MapChanged -= weakEventListener.OnEvent
				};

				valObservableMap.MapChanged += weakEvent.OnEvent;
			}
		}
开发者ID:b3540,项目名称:WindowsStateTriggers,代码行数:52,代码来源:IsNullOrEmptyStateTrigger.cs


示例19: OrientationStateTrigger

		/// <summary>
		/// Initializes a new instance of the <see cref="OrientationStateTrigger"/> class.
		/// </summary>
		public OrientationStateTrigger()
		{
			if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
			{
				var weakEvent =
					new WeakEventListener<OrientationStateTrigger, DisplayInformation, object>(this)
					{
						OnEventAction = (instance, source, eventArgs) => OrientationStateTrigger_OrientationChanged(source, eventArgs),
						OnDetachAction = (instance, weakEventListener) => DisplayInformation.GetForCurrentView().OrientationChanged -= weakEventListener.OnEvent
					};
				DisplayInformation.GetForCurrentView().OrientationChanged += weakEvent.OnEvent;
			}
		}
开发者ID:b3540,项目名称:WindowsStateTriggers,代码行数:16,代码来源:OrientationStateTrigger.cs


示例20: MasterDetailStateTrigger

        public MasterDetailStateTrigger()
        {
            if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                var weakEvent = new WeakEventListener<MasterDetailStateTrigger, ApplicationView, object>(this)
                {
                    OnEventAction = (instance, source, eventArgs) => MasterDetailStatetateTrigger_MasterDetailStateChanged(source, eventArgs),
                    OnDetachAction = (instance, weakEventListener) => ApplicationView.GetForCurrentView().VisibleBoundsChanged -= weakEventListener.OnEvent
                };

                ApplicationView.GetForCurrentView().VisibleBoundsChanged += weakEvent.OnEvent;
            }
        }
开发者ID:BiaoLiu,项目名称:YLP.UWP,代码行数:13,代码来源:MasterDetailStateTrigger.cs



注:本文中的WeakEventListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# WeakFunc类代码示例发布时间:2022-05-24
下一篇:
C# WcfDuplexServiceCallback类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap