forked from microsoft/WPF-Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainWindow.cs
35 lines (31 loc) · 1.18 KB
/
MainWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// // Copyright (c) Microsoft. All rights reserved.
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Windows;
using System.Windows.Controls;
namespace FindingElementInPanel
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private int _cCounter;
public MainWindow()
{
InitializeComponent();
}
private void FindIndex(object sender, RoutedEventArgs e)
{
_cCounter += 1;
// Create a new Text element.
var newText = new TextBlock();
// Add this element to the UIElementCollection of the DockPanel element.
MainDisplayPanel.Children.Add(newText);
// Add a text node under the Text element. This text is displayed.
newText.Text = "New element #" + _cCounter;
DockPanel.SetDock(newText, Dock.Top);
// Display the Index number of the new element.
TxtDisplay.Text = "The Index of the new element is " + MainDisplayPanel.Children.IndexOf(newText);
}
}
}