private void PatternExample()
{
var root = AutomationElement.RootElement;
var window = UITree.Query(root).UsingTreeWalkerEngine()
// Query 1.
.FindChildren().Where()
.Name().Contains("Microsoft Visual Studio")
.And()
.Type().Is(ControlType.Window)
.Select().FirstResult();
var windows = UITree.Query(root).UsingTreeWalkerEngine()
// Query 2.
.FindChildren().Where()
.Name().Contains("Microsoft Visual Studio")
.And()
.Type().Is(ControlType.Window)
.Select().AllResults();
// Execute using the 'Window' pattern.
window.Execute<WindowPattern>(p => p.SetWindowVisualState(WindowVisualState.Minimized));
// Can also be called on a collection of UI components.
windows.Execute<WindowPattern>((p, c) => p.SetWindowVisualState(WindowVisualState.Minimized));
// Or, using the .Pattern() method (only available on single components).
window.Pattern<WindowPattern>().SetWindowVisualState(WindowVisualState.Minimized);
}