'宣言 Public ReadOnly Property UIElement As UltraCalendarComboUIElement
public UltraCalendarComboUIElement UIElement {get;}
Imports Infragistics.Win Imports Infragistics.Win.UltraWinSchedule Imports Infragistics.Win.UltraWinSchedule.CalendarCombo Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim info As String = "The descendant elements of the control's main UIElement are: " + vbCrLf + vbCrLf Me.EnumerateChildElements(Me.ultraCalendarCombo1.UIElement, info) ' Display the UIElement hierarchy in a message box MessageBox.Show(info, "EnumerateUIElements", MessageBoxButtons.OK) End Sub Private Sub EnumerateChildElements(ByVal element As UIElement, ByRef info As String) '---------------------------------------------------------------------------------------------------- ' UIElement ' ' Enumerates the specified UIElement's child elements to display ' the element hierarchy '---------------------------------------------------------------------------------------------------- Dim level As Integer = Me.GetElementLevel(element) Dim tabChar As String = String.Empty Dim i As Integer For i = 0 To level tabChar += Chr(9) Next ' Increment the level for the next iteration, if any level += 1 ' Iterate the specified element's ChildElements collection, Dim child As UIElement For Each child In element.ChildElements ' Output each child element's type name info += tabChar + child.ToString() + vbCrLf ' Call this function recursively to get each child's children, etc. Me.EnumerateChildElements(child, info) Next End Sub ' Returns the "generation" of the specified UIElement; that is, the ' number of ancestor UIElements it has Private Function GetElementLevel(ByVal element As UIElement) Dim level As Integer Dim parentElement As UIElement = element.Parent ' Increment 'level' until we hit a null parent While Not parentElement Is Nothing level += 1 parentElement = parentElement.Parent End While Return level End Function
using Infragistics.Win; using Infragistics.Win.UltraWinSchedule; using Infragistics.Win.UltraWinSchedule.CalendarCombo; private void button1_Click(object sender, System.EventArgs e) { string info = "The descendant elements of the control's main UIElement are: " + "\n" + "\n"; this.EnumerateChildElements( this.ultraCalendarCombo1.UIElement, ref info ); // Display the UIElement hierarchy in a message box MessageBox.Show( info, "EnumerateUIElements", MessageBoxButtons.OK ); } private void EnumerateChildElements( UIElement element, ref string info ) { //---------------------------------------------------------------------------------------------------- // UIElement // // Enumerates the specified UIElement's child elements to display // the element hierarchy //---------------------------------------------------------------------------------------------------- int level = this.GetElementLevel( element ); string tabChar = string.Empty; for ( int i = 0; i <= level; i ++ ) { tabChar += ((char)(9)).ToString(); } // Increment the level for the next iteration, if any level++; // Iterate the specified element's ChildElements collection, foreach( UIElement child in element.ChildElements ) { // Output each child element's type name info += tabChar + child.ToString() + "\n"; // Call this function recursively to get each child's children, etc. this.EnumerateChildElements( child, ref info ); } } // Returns the "generation" of the specified UIElement; that is, the // number of ancestor UIElements it has private int GetElementLevel( UIElement element ) { int level = 0; UIElement parentElement = element.Parent; // Increment 'level' until we hit a null parent while ( parentElement != null ) { level ++; parentElement = parentElement.Parent; } return level; }