System.Windows.Controls.ItemsPresenter.GetDefaultTemplate C# (CSharp) Method

GetDefaultTemplate() private method

private GetDefaultTemplate ( ) : System.Windows.Controls.UIElement
return System.Windows.Controls.UIElement
		internal override UIElement GetDefaultTemplate ()
		{
			// ItemsPresenter only works when it's attached to an ItemsControl
			// but the user may try to attach it to any custom control
			ItemsControl c = TemplateOwner as ItemsControl;
			if (c == null)
				return null;

			if (_elementRoot != null)
				return _elementRoot;

			if (c.ItemsPanel != null) {
				DependencyObject root = c.ItemsPanel.GetVisualTree ();
				if (root != null && !(root is Panel))
					throw new InvalidOperationException ("The root element of an ItemsPanelTemplate must be a Panel subclass");
				_elementRoot = (Panel) root;
			}

#if false
			if (_elementRoot == null) {
				if (c is ListBox)
					_elementRoot = new VirtualizingStackPanel ();
				else
					_elementRoot = new StackPanel ();
			}
#else
			if (_elementRoot == null)
				_elementRoot = new StackPanel ();
#endif
			
			_elementRoot.IsItemsHost = true;
			_elementRoot.TemplateOwner = c;

			return _elementRoot;
		}
	}