private void AddNew(object sender, ExecutedRoutedEventArgs e)
        {
            var newItem    = CreateNewItem(( Type )e.Parameter);
            var properties = newItem.GetType().GetProperties();

            foreach (var property in properties)
            {
                // For Generic Types, add an empty collection/list of T.
                if (property.CanWrite && property.PropertyType.IsGenericType)
                {
                    var genericCollection = Activator.CreateInstance(property.PropertyType);
                    property.SetValue(newItem, genericCollection, null);
                }
            }

            var eventArgs = new ItemAddingEventArgs(ItemAddingEvent, newItem);

            this.RaiseEvent(eventArgs);
            if (eventArgs.Cancel)
            {
                return;
            }
            newItem = eventArgs.Item;

            Items.Add(newItem);

            this.RaiseEvent(new ItemEventArgs(ItemAddedEvent, newItem));

            SelectedItem = newItem;
        }
Esempio n. 2
0
        private void AddNew(object sender, ExecutedRoutedEventArgs e)
        {
            var newItem = CreateNewItem(( Type )e.Parameter);

            var eventArgs = new ItemAddingEventArgs(ItemAddingEvent, newItem);

            this.RaiseEvent(eventArgs);
            if (eventArgs.Cancel)
            {
                return;
            }
            newItem = eventArgs.Item;

            Items.Add(newItem);

            this.RaiseEvent(new ItemEventArgs(ItemAddedEvent, newItem));

            SelectedItem = newItem;
        }
Esempio n. 3
0
        private void AddNewCore(object newItem)
        {
            if (newItem == null)
            {
                throw new ArgumentNullException("newItem");
            }

            var eventArgs = new ItemAddingEventArgs(ItemAddingEvent, newItem);

            this.RaiseEvent(eventArgs);
            if (eventArgs.Cancel)
            {
                return;
            }
            newItem = eventArgs.Item;

            this.Items.Add(newItem);

            this.RaiseEvent(new ItemEventArgs(ItemAddedEvent, newItem));

            this.SelectedItem = newItem;
        }
Esempio n. 4
0
    private void AddNew( object sender, ExecutedRoutedEventArgs e )
    {
      var newItem = CreateNewItem( ( Type )e.Parameter );

      var eventArgs = new ItemAddingEventArgs( ItemAddingEvent, newItem );
      this.RaiseEvent( eventArgs );
      if( eventArgs.Cancel )
        return;
      newItem = eventArgs.Item;

      Items.Add( newItem );

      this.RaiseEvent( new ItemEventArgs( ItemAddedEvent, newItem ) );

      SelectedItem = newItem;
    }