// -----------------------------------------------------------------------
//
// Copyright 2014 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
using System.Linq;
using Perspex.LogicalTree;
using Perspex.Styling;
///
/// Adds common functionality to .
///
public static class ControlExtensions
{
///
/// Tries to being the control into view.
///
/// The control.
public static void BringIntoView(this IControl control)
{
control.BringIntoView(new Rect(control.Bounds.Size));
}
///
/// Tries to being the control into view.
///
/// The control.
/// The area of the control to being into view.
public static void BringIntoView(this IControl control, Rect rect)
{
var ev = new RequestBringIntoViewEventArgs
{
RoutedEvent = Control.RequestBringIntoViewEvent,
TargetObject = control,
TargetRect = rect,
};
control.RaiseEvent(ev);
}
///
/// Finds the named control in the specified control.
///
/// The type of the control to find.
/// The control.
/// The name of the control to find.
/// The control or null if not found.
public static T FindControl(this IControl control, string name) where T : IControl
{
return control.GetLogicalDescendents()
.OfType()
.FirstOrDefault(x => x.Name == name);
}
}
}