本文整理汇总了C#中NotifyCollectionChangedEventHandler类的典型用法代码示例。如果您正苦于以下问题:C# NotifyCollectionChangedEventHandler类的具体用法?C# NotifyCollectionChangedEventHandler怎么用?C# NotifyCollectionChangedEventHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NotifyCollectionChangedEventHandler类属于命名空间,在下文中一共展示了NotifyCollectionChangedEventHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getFeeds
/// <summary>
/// Låter andra klasser lyssna på förändringar i repositoryt så att de kan uppdateras.
/// </summary>
/// <param name="handler"></param>
/// <returns>Referns till en instans av FDRFeedRepository med eventhanterare</returns>
public static IRepository<Feed> getFeeds(NotifyCollectionChangedEventHandler handler)
{
if (feeds == null)
feeds = new FDRFeedRepository();
feeds.CollectionChanged += handler;
return feeds;
}
示例2: GeneratorNodeFactory
public GeneratorNodeFactory( NotifyCollectionChangedEventHandler itemsChangedHandler,
NotifyCollectionChangedEventHandler groupsChangedHandler,
EventHandler<ExpansionStateChangedEventArgs> expansionStateChangedHandler,
EventHandler isExpandedChangingHandler,
EventHandler isExpandedChangedHandler,
DataGridControl dataGridControl )
{
if( itemsChangedHandler == null )
throw new ArgumentNullException( "itemsChangedHandler" );
if( groupsChangedHandler == null )
throw new ArgumentNullException( "groupsChangedHandler" );
if( expansionStateChangedHandler == null )
throw new ArgumentNullException( "expansionStateChangedHandler" );
if( isExpandedChangingHandler == null )
throw new ArgumentNullException( "isExpandedChangingHandler" );
if( isExpandedChangedHandler == null )
throw new ArgumentNullException( "isExpandedChangedHandler" );
m_itemsChangedHandler = itemsChangedHandler;
m_groupsChangedHandler = groupsChangedHandler;
m_expansionStateChangedHandler = expansionStateChangedHandler;
m_isExpandedChangingHandler = isExpandedChangingHandler;
m_isExpandedChangedHandler = isExpandedChangedHandler;
if( dataGridControl != null )
{
m_dataGridControl = new WeakReference( dataGridControl );
}
}
示例3: AddHandler
public void AddHandler(NotifyCollectionChangedEventHandler handler)
{
if(handler != null)
{
_books.CollectionChanged += handler;
}
}
示例4: CollectionChangedEventListener
public CollectionChangedEventListener(INotifyCollectionChanged source, NotifyCollectionChangedEventHandler handler)
{
if (source == null) { throw new ArgumentNullException("source"); }
if (handler == null) { throw new ArgumentNullException("handler"); }
this.source = source;
this.handler = handler;
}
示例5: OnAutoScrollToEndChanged
public static void OnAutoScrollToEndChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
{
var ctrl = s as ItemsControl;
if (ctrl == null)
throw new InvalidOperationException("This attached property only supports ItemsControl or derived types.");
var data = ctrl.Items as INotifyCollectionChanged;
if (data == null)
throw new InvalidOperationException("Collection does not support change notifications.");
Control parentCtrl = ctrl;
while (parentCtrl != null && parentCtrl.GetType() != typeof(ScrollViewer))
parentCtrl = parentCtrl.Parent as Control;
ScrollViewer sv = parentCtrl as ScrollViewer;
var scrollToEndHandler = new NotifyCollectionChangedEventHandler(
(s1, e1) =>
{
if (e1.Action == NotifyCollectionChangedAction.Add && sv != null)
sv.ScrollToBottom();
});
if ((bool)e.NewValue)
data.CollectionChanged += scrollToEndHandler;
else
data.CollectionChanged -= scrollToEndHandler;
}
示例6: OnAutoScrollChanged
public static void OnAutoScrollChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
{
var val = (bool)e.NewValue;
var lb = s as ListView;
if (lb == null)
throw new InvalidOperationException("This behavior can only be attached to a ListView.");
var ic = lb.Items;
var data = ic.SourceCollection as INotifyCollectionChanged;
if (data == null) return;
var autoscroller = new NotifyCollectionChangedEventHandler(
(s1, e1) =>
{
var selectedItem = default(object);
switch (e1.Action)
{
case NotifyCollectionChangedAction.Add:
case NotifyCollectionChangedAction.Move: selectedItem = e1.NewItems[e1.NewItems.Count - 1]; break;
case NotifyCollectionChangedAction.Remove: if (ic.Count < e1.OldStartingIndex) { selectedItem = ic[e1.OldStartingIndex - 1]; } else if (ic.Count > 0) selectedItem = ic[0]; break;
case NotifyCollectionChangedAction.Reset: if (ic.Count > 0) selectedItem = ic[0]; break;
}
if (selectedItem == default(object)) return;
ic.MoveCurrentTo(selectedItem);
lb.ScrollIntoView(selectedItem);
});
if (val) data.CollectionChanged += autoscroller;
else data.CollectionChanged -= autoscroller;
}
示例7: OnAutoScrollToEndChanged
public static void OnAutoScrollToEndChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
{
var listBox = s as ListBox;
if(listBox==null)
return;
var listBoxItems = listBox.Items;
var data = listBoxItems.SourceCollection as INotifyCollectionChanged;
if (data == null)
return;
var scrollToEndHandler = new NotifyCollectionChangedEventHandler(
(s1, e1) =>
{
if (listBox.Items.Count <= 0)
return;
var lastItem = listBox.Items[listBox.Items.Count - 1];
listBoxItems.MoveCurrentTo(lastItem);
listBox.ScrollIntoView(lastItem);
});
if ((bool)e.NewValue)
data.CollectionChanged += scrollToEndHandler;
else
data.CollectionChanged -= scrollToEndHandler;
}
示例8: getCategories
/// <summary>
/// Låter andra klasser lyssna på förändringar i repositoryt så att de kan uppdateras.
/// </summary>
/// <param name="handler"></param>
/// <returns>Referns till en instans av FDRCategoryRepository med eventhanterare</returns>
public static IRepository<Category> getCategories(NotifyCollectionChangedEventHandler handler)
{
if (categories == null)
categories = new FDRCategoryRepository();
categories.CollectionChanged += handler;
return categories;
}
示例9: HookupToCollectionChanged
/// <summary>
/// Hookups the handler to the collection changed event. When the value changes it removes the handler.
/// </summary>
/// <param name="oldValue">The old collection.</param>
/// <param name="newValue">The new collection.</param>
/// <param name="handler">The handler to hookup.</param>
public static void HookupToCollectionChanged(INotifyCollectionChanged oldValue, INotifyCollectionChanged newValue,
NotifyCollectionChangedEventHandler handler)
{
if (oldValue != null)
oldValue.CollectionChanged -= handler;
if (newValue != null)
newValue.CollectionChanged += handler;
}
示例10: AddWeakEventListener
/// <summary>
/// Adds a weak event listener for a CollectionChanged event.
/// </summary>
/// <param name="source">The source of the event.</param>
/// <param name="handler">The event handler.</param>
/// <exception cref="ArgumentNullException">source must not be <c>null</c>.</exception>
/// <exception cref="ArgumentNullException">handler must not be <c>null</c>.</exception>
protected void AddWeakEventListener(INotifyCollectionChanged source, NotifyCollectionChangedEventHandler handler)
{
if (source == null) { throw new ArgumentNullException("source"); }
if (handler == null) { throw new ArgumentNullException("handler"); }
CollectionChangedEventListener listener = new CollectionChangedEventListener(source, handler);
collectionChangedListeners.Add(listener);
CollectionChangedEventManager.AddListener(source, listener);
}
示例11: Subscribe
private static void Subscribe(DataGrid dataGrid)
{
var handler = new NotifyCollectionChangedEventHandler((sender, eventArgs) => ScrollToEnd(dataGrid));
if (handlersDict.ContainsKey(dataGrid))
{
return;
}
handlersDict.Add(dataGrid, handler);
((INotifyCollectionChanged)dataGrid.Items).CollectionChanged += handler;
ScrollToEnd(dataGrid);
}
示例12: SetupOnUnloadedHandler
private static void SetupOnUnloadedHandler(DependencyObject dependencyObject, INotifyCollectionChanged observableCollection,
NotifyCollectionChangedEventHandler sourceChangedHandler)
{
RoutedEventHandler unloadedEventHandler = null;
unloadedEventHandler = (sender, args) =>
{
observableCollection.CollectionChanged -= sourceChangedHandler;
((ListViewBase)sender).SelectionChanged -= OnGridSelectionChanged;
((ListViewBase)sender).Unloaded -= unloadedEventHandler;
};
((ListViewBase)dependencyObject).Unloaded += unloadedEventHandler;
}
示例13: RemoveEventListener
protected void RemoveEventListener(INotifyCollectionChanged source, NotifyCollectionChangedEventHandler handler)
{
if (source == null) { throw new ArgumentException("source"); }
if (handler == null) { throw new ArgumentException("handler"); }
CollectionChangedEventListener listener = collectionEventListeners.LastOrDefault(c => c.Source == source && c.Handler == handler);
if (listener != null)
{
collectionEventListeners.Remove(listener);
CollectionChangedEventManager.RemoveListener(source, listener);
}
}
示例14: DataMappingViewModel
public DataMappingViewModel(IWebActivity activity, NotifyCollectionChangedEventHandler mappingCollectionChangedEventHandler = null)
{
_activity = activity;
_actionManager = new ActionManager();
Inputs = new ObservableCollection<IInputOutputViewModel>();
Outputs = new ObservableCollection<IInputOutputViewModel>();
if(mappingCollectionChangedEventHandler != null)
{
Inputs.CollectionChanged += mappingCollectionChangedEventHandler;
Outputs.CollectionChanged += mappingCollectionChangedEventHandler;
}
Initialize(_activity);
}
示例15: ItemsSourceCollectionViewSource
public ItemsSourceCollectionViewSource([NotNull] UICollectionView collectionView,
string itemTemplate = AttachedMemberConstants.ItemTemplate)
: base(collectionView, itemTemplate)
{
_weakHandler = ReflectionExtensions.MakeWeakCollectionChangedHandler(this,
(adapter, o, arg3) => adapter.OnCollectionChanged(o, arg3));
}