xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.IndexOfSample"
WindowTitle="UIElementCollection IndexOf Sample">
Text 1
Text 2
//File:Window.xaml.cs
namespace WpfApplication1 {
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
public partial class IndexOfSample {
void FindIndex(object sender, RoutedEventArgs e)
{
TextBlock newText = new TextBlock();
MainDisplayPanel.Children.Add(newText);
newText.Text = "New element #" ;
DockPanel.SetDock(newText,Dock.Top);
TxtDisplay.Text = MainDisplayPanel.Children.IndexOf(newText)+"";
}
}
}