本文整理汇总了C#中WeakEventListener类的典型用法代码示例。如果您正苦于以下问题:C# WeakEventListener类的具体用法?C# WeakEventListener怎么用?C# WeakEventListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WeakEventListener类属于命名空间,在下文中一共展示了WeakEventListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例5: Handler
private void Handler()
{
var propertyChangedListener = new WeakEventListener<PopUpSearchView, ListBox, SelectionChangedEventArgs>(this, ListBoxItems);
ListBoxItems.SelectionChanged += propertyChangedListener.OnEvent;
propertyChangedListener.OnEventAction += ValuePropertyChanged;
propertyChangedListener.OnDetachAction += Static;
}
示例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;
}
示例7: SearchListView
public SearchListView()
{
InitializeComponent();
var dataContextChangedListener =
new WeakEventListener<SearchListView, SearchListView, DependencyPropertyChangedEventArgs>(this, this);
DataContextChanged += dataContextChangedListener.OnEvent;
dataContextChangedListener.OnEventAction = OnDataContextChanged;
dataContextChangedListener.OnDetachAction = OnDetachDataContextChanged;
}
示例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 );
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}