Exemplo n.º 1
0
        /// <summary>
        /// Creates new collection form and hooks up events.
        /// </summary>
        /// <returns></returns>
        protected override CollectionForm CreateCollectionForm()
        {
            var form  = base.CreateCollectionForm();
            var table = ((form as Form).Controls[0] as TableLayoutPanel);

            if (table != null)
            {
                // Hook up property changed event
                if (table.Controls[5] is PropertyGrid propertyGrid)
                {
                    propertyGrid.PropertyValueChanged += (sender, args) => CollectionPropertyChanged?.Invoke(this, args);
                }

                // Hook up collection changed event to add and remove buttons
                if (table.Controls[1].Controls[0] is Button addButton)
                {
                    addButton.Click += this.OnAdd;
                }
                if (table.Controls[1].Controls[1] is Button removeButton)
                {
                    removeButton.Click += this.OnRemove;
                }

                // Hook up form closed event
                form.FormClosed += (sender, args) => FormClosed?.Invoke(this, args);
            }

            return(form);
        }
Exemplo n.º 2
0
        /// <summary>
        /// プロパティ変更時のイベント
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnPropertyChanged(object?sender, PropertyChangedEventArgs e)
        {
            if (sender is null)
            {
                throw new InvalidOperationException();
            }

            CollectionPropertyChanged?.Invoke(sender, e);

            // 非同期版イベントが購読されていなければ何もしない
            var handler = CollectionPropertyChangedAsync;

            if (handler is null)
            {
                return;
            }

            await Task.WhenAll(
                handler.GetInvocationList()
                .OfType <NotifyPropertyChangedEventAsync>()
                .Select(async(x) => await x.Invoke(sender, e)));
        }
 protected virtual void OnCollectionPropertyChanged(object sender, [CallerMemberName] string propertyName = null)
 {
     CollectionPropertyChanged?.Invoke(sender, new PropertyChangedEventArgs(propertyName));
 }