Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
PopulatingEventArgs Class
Collapse the table of content
Expand the table of content

PopulatingEventArgs Class


Provides data for the AutoCompleteBox.Populating event.


Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Input (in System.Windows.Controls.Input.dll)

public class PopulatingEventArgs : RoutedEventArgs

The PopulatingEventArgs type exposes the following members.

Public methodPopulatingEventArgsInitializes a new instance of the PopulatingEventArgs class.

Public propertyCancelGets or sets a value that indicates whether the Populating event should be canceled.
Public propertyOriginalSourceGets a reference to the object that raised the event. (Inherited from RoutedEventArgs.)
Public propertyParameterGets the text that is used to determine which items to display in the AutoCompleteBox control.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Run this sample

The following example shows how to use the ItemContainerGenerator to expand all the nodes of a TreeView when the mouse enters the control.

public partial class MainPage : UserControl
    // Create the topics collection.
    static public ObservableCollection<Topic> Topics =
        new ObservableCollection<Topic>();
    public MainPage()

        // Add some topics to the collection.
        Topic UsingControls = new Topic("Using Controls and Dialog Boxes", Guid.NewGuid());
        UsingControls.ChildTopics.Add(new Topic("Getting Started with Controls", Guid.NewGuid()));
        Topic DataGridTopic = new Topic("DataGrid", Guid.NewGuid());
            new Topic("Default Keyboard and Mouse Behavior in the DataGrid Control",
            new Topic("How to: Add a DataGrid Control to a Page",
            new Topic("How to: Display and Configure Row Details in the DataGrid Control",
        UsingControls.ChildTopics.Add(new Topic("Ink Presenter", Guid.NewGuid()));
        myTreeView.DataContext = Topics;

    void myTreeView_MouseEnter(object sender, MouseEventArgs e)
        ExpandAll(sender, e);

    // Method to expand all the treeview children.
    private void ExpandAll(object sender, RoutedEventArgs e)
        for (int i = 0; i < myTreeView.Items.Count; i++)
            TreeViewItem childItem =
                    as TreeViewItem;
            if (childItem != null)

    // Declare a delegate for the method to expand all children. You'll do this
    // asynchronously to ensure the items are instatiated before they are expanded. 
    public delegate void ExpandChildren(TreeViewItem currentTreeViewItem);

    // Exapand all the children of the current treeview item.
    private void ExpandAllTreeViewItems(TreeViewItem currentTreeViewItem)
        // If the current node is not expanded, call the expansion asynchronously 
        // to ensure the items are instantiated before expansion.
        if (!currentTreeViewItem.IsExpanded)
            currentTreeViewItem.IsExpanded = true;

            // Asynchronous  call to expand the children.
                new object[] { currentTreeViewItem });

            // Alternatively, you could make the call to ExpandAllTreeViewItems
            // using lambda syntax.
            // currentTreeViewItem.Dispatcher.BeginInvoke(() => 
            //   ExpandAllTreeViewItems(currentTreeViewItem));

            for (int i = 0; i < currentTreeViewItem.Items.Count; i++)
                TreeViewItem child = (TreeViewItem)

    // Simple business object.
    public class Topic
        public string Title { get; set; }
        public Guid Id { get; set; }
        public ObservableCollection<Topic> ChildTopics { get; set; }
        public Topic()
            ChildTopics = new ObservableCollection<Topic>();
        public Topic(string title, Guid idValue)
            : this()
            Title = title;
            Id = idValue;

<StackPanel x:Name="LayoutRoot" Background="White">
        <sdk:HierarchicalDataTemplate x:Key="ChildTemplate" ItemsSource="{Binding Path=ChildTopics}"  >
            <TextBlock FontStyle="Italic" Text="{Binding Path=Title}"  />
        <sdk:HierarchicalDataTemplate x:Key="RootTemplate" 
            ItemsSource="{Binding Path=ChildTopics}" 
            ItemTemplate="{StaticResource ChildTemplate}">
            <TextBlock Text="{Binding Path=Title}" FontWeight="Bold" />
    <sdk:TreeView Width="400" Height="200" ItemsSource="{Binding}" 
        ItemTemplate="{StaticResource RootTemplate}" x:Name="myTreeView" 
        MouseEnter="myTreeView_MouseEnter" />


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

© 2015 Microsoft