Naming and locating controls
It is only possible to perform actions on controls in the UI if they can be located. None of the controls in the preceding examples have been given names. Locating one of the buttons in a StackPanel
, for example, is difficult as it stands.
Returning to the StackPanel
example, it has three buttons:
$xaml = [xml]'<?xml version="1.0" encoding="utf-8"?>
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="350" Height="350">
<StackPanel Width="50">
<Button Content="Button1" />
<Button Content="Button2" />
<Button Content="Button3" />
</StackPanel>
</Window>'
$window = [System.Windows.Markup.XamlReader]::Load(
[System.Xml.XmlNodeReader]$xaml
)
Accessing the Text
property...