protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { //Limito l'accesso da parte di altri Thread che vogliono modificare la collection using (BlockReentrancy()) { System.Collections.Specialized.NotifyCollectionChangedEventHandler eventHandler = CollectionChanged; if (eventHandler == null) { return; } Delegate[] delegates = eventHandler.GetInvocationList(); // Walk thru invocation list foreach (System.Collections.Specialized.NotifyCollectionChangedEventHandler handler in delegates) { DispatcherObject dispatcherObject = handler.Target as DispatcherObject; // If the subscriber is a DispatcherObject and different thread if (dispatcherObject != null && dispatcherObject.CheckAccess() == false) { // Invoke handler in the target dispatcher's thread dispatcherObject.Dispatcher.Invoke(DispatcherPriority.DataBind, handler, this, e); } else // Execute handler as is { handler(this, e); } } } }
protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { // Be nice - use BlockReentrancy like MSDN said using (BlockReentrancy()) { System.Collections.Specialized.NotifyCollectionChangedEventHandler eventHandler = CollectionChanged; if (eventHandler == null) { return; } Delegate[] delegates = eventHandler.GetInvocationList(); // Walk thru invocation list foreach (System.Collections.Specialized.NotifyCollectionChangedEventHandler handler in delegates) { DispatcherObject dispatcherObject = handler.Target as DispatcherObject; // If the subscriber is a DispatcherObject and different thread if (dispatcherObject != null) { // Invoke handler in the target dispatcher's thread dispatcherObject.Dispatcher.Invoke(DispatcherPriority.DataBind, handler, this, e); } } } }
public static TBindable WithTabbedPagePagesChangedEvent <TBindable>(this TBindable self, System.Collections.Specialized.NotifyCollectionChangedEventHandler handlerAction) where TBindable : TabbedPage { self.PagesChanged += handlerAction; return(self); }
/// <summary> /// This method will be called when the AutoScrollToEnd /// property was changed /// </summary> /// <param name="s">The sender (the ListBox)</param> /// <param name="e">Some additional information</param> public static void OnAutoScrollToEndChanged(DependencyObject s, DependencyPropertyChangedEventArgs e) { var listBox = s as ListBox; if (listBox != null) { var listBoxItems = listBox.Items; var data = listBoxItems.SourceCollection as INotifyCollectionChanged; var scrollToEndHandler = new System.Collections.Specialized.NotifyCollectionChangedEventHandler( (s1, e1) => { if (listBox.Items.Count > 0) { listBoxItems.MoveCurrentToLast(); listBox.ScrollIntoView(listBoxItems.CurrentItem); } }); if ((bool)e.NewValue) { data.CollectionChanged += scrollToEndHandler; } else { data.CollectionChanged -= scrollToEndHandler; } } }
protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { // Be nice - use BlockReentrancy like MSDN said using (BlockReentrancy()) { System.Collections.Specialized.NotifyCollectionChangedEventHandler eventHandler = CollectionChanged; if (eventHandler == null) { return; } Delegate[] delegates = eventHandler.GetInvocationList(); // Walk thru invocation list foreach (System.Collections.Specialized.NotifyCollectionChangedEventHandler handler in delegates) { DispatcherObject dispatcherObject = handler.Target as DispatcherObject; // If the subscriber is a DispatcherObject and different thread if (dispatcherObject != null && dispatcherObject.CheckAccess() == false) { // Invoke handler in the target dispatcher's thread dispatcherObject.Dispatcher.BeginInvoke(DispatcherPriority.DataBind, handler, this, e); dispatcherObject.Dispatcher.UnhandledException += new DispatcherUnhandledExceptionEventHandler(DispatcherUnhandledException); dispatcherObject.Dispatcher.UnhandledExceptionFilter += new DispatcherUnhandledExceptionFilterEventHandler(DispatcherUnhandledExceptionFilter); } else // Execute handler as is { handler(this, e); } } } }
public NotificationsMenuItem(Notifications.NotificationsViewExtension notificationsExtension) { this.notificationsModel = notificationsExtension; InitializeComponent(); var showItem = new MenuItem(); showItem.Header = Properties.Resources.Display; showItem.Click += (o, e) => { //create a window to display the list of notificationsModels var window = new NotificationsView(notificationsExtension); window.Show(); }; var dismissItem = new MenuItem(); dismissItem.Header = Properties.Resources.Dismiss; dismissItem.Click += (o, e) => { this.notificationsModel.Notifications.Clear(); }; //set some defaults dismissItem.IsEnabled = false; showItem.IsEnabled = false; BadgeGrid.Visibility = Visibility.Hidden; this.MenuItem.Items.Add(showItem); this.MenuItem.Items.Add(dismissItem); //create our icon var color = new SolidColorBrush(Colors.LightGray); this.imageicon.Source = FontAwesome.WPF.ImageAwesome.CreateImageSource(FontAwesome.WPF.FontAwesomeIcon.ExclamationCircle, color); //create some bindings //attach the visibility of the badge and menuItems enabledState to the number of notifications without a binding... NotificationsChangeHandler = (o, e) => { if (this.notificationsModel.Notifications.Count > 0) { BadgeGrid.Visibility = Visibility.Visible; dismissItem.IsEnabled = true; showItem.IsEnabled = true; } else { BadgeGrid.Visibility = Visibility.Hidden; dismissItem.IsEnabled = false; showItem.IsEnabled = false; } }; this.notificationsModel.Notifications.CollectionChanged += NotificationsChangeHandler; // create a binding between the label and the count of notifications var binding = new Binding(); binding.Path = new PropertyPath("Notifications.Count"); //dataContext is the extension CountLabel.DataContext = notificationsExtension; CountLabel.SetBinding(TextBlock.TextProperty, binding); }
public NotificationsMenuItem(Notifications.NotificationsViewExtension notificationsExtension) { this.notificationsModel = notificationsExtension; InitializeComponent(); var showItem = new MenuItem(); showItem.Header = Properties.Resources.Display; showItem.Click += (o, e) => { //create a window to display the list of notificationsModels var window = new NotificationsView(notificationsExtension); window.Show(); }; var dismissItem = new MenuItem(); dismissItem.Header = Properties.Resources.Dismiss; dismissItem.Click += (o, e) => { this.notificationsModel.Notifications.Clear(); }; //set some defaults dismissItem.IsEnabled = false; showItem.IsEnabled = false; BadgeGrid.Visibility = Visibility.Hidden; this.MenuItem.Items.Add(showItem); this.MenuItem.Items.Add(dismissItem); //create our icon var color = new SolidColorBrush(Colors.LightGray); this.imageicon.Source = FontAwesome.WPF.ImageAwesome.CreateImageSource(FontAwesome.WPF.FontAwesomeIcon.ExclamationCircle, color); //create some bindings //attach the visibility of the badge and menuItems enabledState to the number of notifications without a binding... NotificationsChangeHandler = (o, e) => { if (this.notificationsModel.Notifications.Count > 0) { BadgeGrid.Visibility = Visibility.Visible; dismissItem.IsEnabled = true; showItem.IsEnabled = true; } else { BadgeGrid.Visibility = Visibility.Hidden; dismissItem.IsEnabled = false; showItem.IsEnabled = false; } }; this.notificationsModel.Notifications.CollectionChanged += NotificationsChangeHandler; // create a binding between the label and the count of notifications var binding = new Binding(); binding.Path = new PropertyPath("Notifications.Count"); //dataContext is the extension CountLabel.DataContext = notificationsExtension; CountLabel.SetBinding(TextBlock.TextProperty, binding); }
public static void CollectionChangedProcess <T>(T obj, System.Collections.Specialized.NotifyCollectionChangedEventHandler collectionChanged, System.Collections.Specialized.NotifyCollectionChangedEventArgs arg) { #if PWindow if (CIPlatform.Instance.PlayMode == CIPlatform.enPlayMode.Game) { return; } CollectionChangedProcessImpl <T>(obj, collectionChanged, arg); #endif }
public CollectionProperty(System.Collections.Specialized.NotifyCollectionChangedEventHandler onCollectionChanged, params TValue[] values) : base(new ObservableCollection <TValue>()) { if (onCollectionChanged != null) { Value.CollectionChanged += onCollectionChanged; } foreach (var value in values) { Value.Add(value); } }
public ItemsGroupBox() { CommandBindings.Add(new CommandBinding(SelectPrevious, ExecutedSelectedPrevious, CanExecuteSelectPrevious)); CommandBindings.Add(new CommandBinding(SelectNext, ExecutedSelectedNext, CanExecuteSelectNext)); CommandBindings.Add(new CommandBinding(Unlock, ExecutedUnlock, CanExecuteUnlock)); CommandBindings.Add(new CommandBinding(AddNew, ExecutedAddNew, CanExecuteAddNew)); LockIcon = ImageCache.GetImage("pack://application:,,,/BioLink.Client.Extensibility;component/images/Locked.png"); _collectionChangedHandler = (s, e) => UpdateCurrentPosition(); }
public ItemsGroupBox() { CommandBindings.Add(new CommandBinding(SelectPrevious, ExecutedSelectedPrevious, CanExecuteSelectPrevious)); CommandBindings.Add(new CommandBinding(SelectNext, ExecutedSelectedNext, CanExecuteSelectNext)); CommandBindings.Add(new CommandBinding(Unlock, ExecutedUnlock, CanExecuteUnlock)); CommandBindings.Add(new CommandBinding(AddNew, ExecutedAddNew, CanExecuteAddNew)); LockIcon = ImageCache.GetImage("pack://application:,,,/BioLink.Client.Extensibility;component/images/Locked.png"); _collectionChangedHandler = (s, e) => UpdateCurrentPosition(); }
protected override bool Dispose(bool explicitDispose) { if (!base.Dispose(explicitDispose)) { return(false); } if (explicitDispose) { _Handler = null; } return(true); }
/// <summary> /// Invokes event with given parameter. /// </summary> public static void Invoke(System.Collections.Specialized.NotifyCollectionChangedEventHandler eventHandler, object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { #if !DISABLE_INTERLOCKED System.Collections.Specialized.NotifyCollectionChangedEventHandler eh = Interlocked.CompareExchange(ref eventHandler, null, null); #else System.Collections.Specialized.NotifyCollectionChangedEventHandler eh = eventHandler; #endif if (eh != null) { eh(sender, e); } }
public Playlist() { Name = StringTable.UnsavedPlaylist; DispatcherTimer playlistDispatcherTimer = new DispatcherTimer(); playlistDispatcherTimer.Interval = TimeSpan.FromMilliseconds(100); playlistDispatcherTimer.Tick += new EventHandler(playlistDispatcherTimer_Tick); playlistDispatcherTimer.Start(); CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Playlist_CollectionChanged); }
public void ErrorUpdates() { ValidationSummaryTestPage page = new ValidationSummaryTestPage(); this.TestPanel.Children.Add(page); ValidationSummary vs = page.validationSummary; this.EnqueueConditional(() => { return(page.validationSummary.Initialized); }); this.EnqueueCallback(() => { Assert.IsNotNull(vs); BindingExpression be = page.nameTextBox.GetBindingExpression(TextBox.TextProperty); Assert.IsNotNull(be); // Cause a validation error via the input control page.nameTextBox.Text = "ABCDEFG!@#$"; ReadOnlyObservableCollection <ValidationError> errors = Validation.GetErrors(page.nameTextBox); Assert.AreEqual(1, errors.Count); Assert.AreEqual(1, vs.Errors.Count); Assert.AreEqual(errors[0].Exception.Message, vs.Errors[0].Message); Assert.IsTrue(vs.HasErrors); // Fix the error page.nameTextBox.Text = "abcd"; errors = Validation.GetErrors(page.nameTextBox); Assert.AreEqual(0, errors.Count); Assert.AreEqual(0, vs.Errors.Count); Assert.IsFalse(vs.HasErrors); // Check ValidationErrorCollection page.nameTextBox.Text = "ABCDEFG!@#$"; ValidationSummaryItem newError = new ValidationSummaryItem(null, "new error", ValidationSummaryItemType.ObjectError, null, null); ValidationItemCollection errorCollection = vs.Errors as ValidationItemCollection; System.Collections.Specialized.NotifyCollectionChangedEventHandler handler = new System.Collections.Specialized.NotifyCollectionChangedEventHandler( delegate(object o, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { Assert.AreEqual(newError, e.NewItems[0], "new error does not match"); }); errorCollection.CollectionChanged += handler; Assert.AreEqual(1, errorCollection.Count); errorCollection.Add(newError); errorCollection.CollectionChanged -= handler; Assert.AreEqual(2, errorCollection.Count); errorCollection.ClearErrors(ValidationSummaryItemType.ObjectError); Assert.AreEqual(1, errorCollection.Count); }); EnqueueTestComplete(); }
private static void CollectionChangedProcessImpl <T>(T obj, System.Collections.Specialized.NotifyCollectionChangedEventHandler collectionChanged, System.Collections.Specialized.NotifyCollectionChangedEventArgs arg) { #if PWindow if (CIPlatform.Instance.PlayMode == CIPlatform.enPlayMode.Game) { return; } EngineNS.CEngine.Instance.EventPoster.RunOn(() => { collectionChanged?.Invoke(obj, arg); return(true); }, EngineNS.Thread.Async.EAsyncTarget.Main); #endif }
public EventHandle4NotifyCollectionChangedEventHandler( [NotNull] IEventSource eventSource, object destination, System.Collections.Specialized.NotifyCollectionChangedEventHandler handler, string destinationUid, object source, string eventName ) : base( eventSource: eventSource, destination: destination, handler: handler, destinationUid: destinationUid, source: source, eventName: eventName ) { _Handler = handler; }
void FireCollectionChanged(object obj, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) { if (CollectionChanged != null) { #if WINDOWS_PHONE System.Windows.Deployment.Current.Dispatcher.BeginInvoke(new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SafeFireCollectionChanged), this, args); #elif MONO CollectionChanged(obj, args); #else System.Collections.Specialized.NotifyCollectionChangedEventHandler eventHandler = CollectionChanged; if (eventHandler == null) { return; } Delegate[] delegates = eventHandler.GetInvocationList(); // Walk thru invocation list foreach (System.Collections.Specialized.NotifyCollectionChangedEventHandler handler in delegates) { DispatcherObject dispatcherObject = handler.Target as DispatcherObject; // If the subscriber is a DispatcherObject and different thread if (dispatcherObject != null && dispatcherObject.CheckAccess() == false) { // Invoke handler in the target dispatcher's thread dispatcherObject.Dispatcher.Invoke(DispatcherPriority.DataBind, handler, this, args); } else // Execute handler as is { handler(this, args); } } //System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SafeFireCollectionChanged), // this, args); #endif } }
protected override void OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { using (BlockReentrancy()) { System.Collections.Specialized.NotifyCollectionChangedEventHandler eventHandler = CollectionChanged; if (eventHandler == null) { return; } Delegate[] delegates = eventHandler.GetInvocationList(); foreach (System.Collections.Specialized.NotifyCollectionChangedEventHandler handler in delegates) { DispatcherObject dispatcherObject = handler.Target as DispatcherObject; if (dispatcherObject != null && !dispatcherObject.CheckAccess()) { dispatcherObject.Dispatcher.Invoke(DispatcherPriority.DataBind, handler, this, e); } else { handler(this, e); } } } }
private void Initialize() { Visibility = ViewStates.Gone; _popupsCollectionChangedHandler = new WeakEventHandler <System.Collections.Specialized.NotifyCollectionChangedEventArgs>(Popups_CollectionChanged).Handler; }
/// <summary> /// Construtor padrão. /// </summary> /// <param name="dispatcher">Dispatcher que será utilizado pela instancia.</param> /// <param name="action">Ação que será acionada.</param> public CollectionChangedWrapperEventData(Colosoft.Threading.IDispatcher dispatcher, System.Collections.Specialized.NotifyCollectionChangedEventHandler action) : this(dispatcher, action, NotifyCollectionChangedDispatcherPriority.Normal) { }
public CsvConfigCollection() { PropertyChanged += new PropertyChangedEventHandler(CsvConfigs_PropertyChanged); CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(CsvConfigs_CollectionChanged); }
/// <summary> /// Construtor padrão. /// </summary> /// <param name="dispatcher">Dispatcher que será utilizado pela instancia.</param> /// <param name="action">Ação que será acionada.</param> /// <param name="priority">Prioridade;</param> public CollectionChangedWrapperEventData(Colosoft.Threading.IDispatcher dispatcher, System.Collections.Specialized.NotifyCollectionChangedEventHandler action, NotifyCollectionChangedDispatcherPriority priority) { _dispatcher = dispatcher; _action = action; _priority = priority; }