다음을 통해 공유


PopulatingEventArgs Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Provides data for the AutoCompleteBox.Populating event.

Inheritance Hierarchy

System.Object
  System.EventArgs
    System.Windows.RoutedEventArgs
      System.Windows.Controls.PopulatingEventArgs

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

Syntax

'Declaration
Public Class PopulatingEventArgs _
    Inherits RoutedEventArgs
public class PopulatingEventArgs : RoutedEventArgs

The PopulatingEventArgs type exposes the following members.

Constructors

  Name Description
Public method PopulatingEventArgs Initializes a new instance of the PopulatingEventArgs class.

Top

Properties

  Name Description
Public property Cancel Gets or sets a value that indicates whether the Populating event should be canceled.
Public property OriginalSource Gets a reference to the object that raised the event. (Inherited from RoutedEventArgs.)
Public property Parameter Gets the text that is used to determine which items to display in the AutoCompleteBox control.

Top

Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Examples

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.

Partial Public Class MainPage
    Inherits UserControl

    ' Create the topics collection. 
    Public Shared Topics As New ObservableCollection(Of Topic)()
    Public Sub New()
        InitializeComponent()

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

    End Sub

    Private Sub myTreeView_MouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs)
        ExpandAll(sender, e)
    End Sub

    Private Sub ExpandAll(ByVal sender As Object, ByVal e As RoutedEventArgs)
        For i As Integer = 0 To myTreeView.Items.Count - 1
            Dim childItem As TreeViewItem = _
                TryCast(myTreeView.ItemContainerGenerator.ContainerFromItem(myTreeView.Items(i)),  _
                    TreeViewItem)
            If childItem IsNot Nothing Then
                ExpandAllTreeViewItems(childItem)
            End If
        Next
    End Sub

    ' Declare a delegate for the method to expand all children. 
    Public Delegate Sub ExpandChildren(ByVal currentTreeViewItem As TreeViewItem)

    '   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. 
    Private Sub ExpandAllTreeViewItems(ByVal currentTreeViewItem As TreeViewItem)
        If Not currentTreeViewItem.IsExpanded Then

            currentTreeViewItem.IsExpanded = True

            ' Call this method asynchronously to ensure the items are 
            ' instantiated before expansion. 
            currentTreeViewItem.Dispatcher.BeginInvoke( _
                New ExpandChildren(AddressOf ExpandAllTreeViewItems), _
                New Object() {currentTreeViewItem})
        Else

            For i As Integer = 0 To currentTreeViewItem.Items.Count - 1
                Dim child As TreeViewItem = _
                    DirectCast(currentTreeViewItem.ItemContainerGenerator.ContainerFromIndex(i),  _
                    TreeViewItem)
                ExpandAllTreeViewItems(child)
            Next
        End If
    End Sub

    ' Simple business object. 
    Public Class Topic
        Private _Title As String
        Public Property Title() As String
            Get
                Return _Title
            End Get
            Set(ByVal value As String)
                _Title = value
            End Set
        End Property
        Private _Id As Guid
        Public Property Id() As Guid
            Get
                Return _Id
            End Get
            Set(ByVal value As Guid)
                _Id = value
            End Set
        End Property
        Private _ChildTopics As ObservableCollection(Of Topic)
        Public Property ChildTopics() As ObservableCollection(Of Topic)
            Get
                Return _ChildTopics
            End Get
            Set(ByVal value As ObservableCollection(Of Topic))
                _ChildTopics = value
            End Set
        End Property
        Public Sub New()
            ChildTopics = New ObservableCollection(Of Topic)()
        End Sub
        Public Sub New(ByVal title__1 As String, ByVal idValue As Guid)
            Me.New()
            Title = title__1
            Id = idValue
        End Sub
    End Class
End Class
public partial class MainPage : UserControl
{
    // Create the topics collection.
    static public ObservableCollection<Topic> Topics =
        new ObservableCollection<Topic>();
    public MainPage()
    {
        InitializeComponent();

        // 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());
        DataGridTopic.ChildTopics.Add(
            new Topic("Default Keyboard and Mouse Behavior in the DataGrid Control",
                Guid.NewGuid()));
        DataGridTopic.ChildTopics.Add(
            new Topic("How to: Add a DataGrid Control to a Page",
                Guid.NewGuid()));
        DataGridTopic.ChildTopics.Add(
            new Topic("How to: Display and Configure Row Details in the DataGrid Control",
                Guid.NewGuid()));
        UsingControls.ChildTopics.Add(DataGridTopic);
        UsingControls.ChildTopics.Add(new Topic("Ink Presenter", Guid.NewGuid()));
        Topics.Add(UsingControls);
        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 =
                myTreeView.ItemContainerGenerator.ContainerFromItem(myTreeView.Items[i])
                    as TreeViewItem;
            if (childItem != null)
                ExpandAllTreeViewItems(childItem);
        }
    }

    // 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.
            currentTreeViewItem.Dispatcher.BeginInvoke(new
                ExpandChildren(ExpandAllTreeViewItems),
                new object[] { currentTreeViewItem });

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

        else
        {
            for (int i = 0; i < currentTreeViewItem.Items.Count; i++)
            {
                TreeViewItem child = (TreeViewItem)
                    currentTreeViewItem.ItemContainerGenerator.ContainerFromIndex(i);
                ExpandAllTreeViewItems(child);
            }
        }
    }

    // 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">
    <StackPanel.Resources>
        <sdk:HierarchicalDataTemplate x:Key="ChildTemplate" ItemsSource="{Binding Path=ChildTopics}"  >
            <TextBlock FontStyle="Italic" Text="{Binding Path=Title}"  />
        </sdk:HierarchicalDataTemplate>
        <sdk:HierarchicalDataTemplate x:Key="RootTemplate" 
            ItemsSource="{Binding Path=ChildTopics}" 
            ItemTemplate="{StaticResource ChildTemplate}">
            <TextBlock Text="{Binding Path=Title}" FontWeight="Bold" />
        </sdk:HierarchicalDataTemplate>
    </StackPanel.Resources>
    <sdk:TreeView Width="400" Height="200" ItemsSource="{Binding}" 
        ItemTemplate="{StaticResource RootTemplate}" x:Name="myTreeView" 
        MouseEnter="myTreeView_MouseEnter" />
  </StackPanel>

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

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

Thread Safety

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