csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
// -----------------------------------------------------------------------
|
|
// <copyright file="ControlExtensions.cs" company="Steven Kirk">
|
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|
// </copyright>
|
|
// -----------------------------------------------------------------------
|
|
|
|
namespace Perspex.Controls
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Perspex.Controls;
|
|
using Perspex.LogicalTree;
|
|
using Perspex.Styling;
|
|
using Perspex.VisualTree;
|
|
|
|
public static class ControlExtensions
|
|
{
|
|
public static T FindControl<T>(this Control control, string id) where T : Control
|
|
{
|
|
return control.GetLogicalDescendents()
|
|
.OfType<T>()
|
|
.FirstOrDefault(x => x.Id == id);
|
|
}
|
|
|
|
public static IEnumerable<Control> GetTemplateControls(this ITemplatedControl control)
|
|
{
|
|
var visual = control as IVisual;
|
|
|
|
if (visual != null)
|
|
{
|
|
return visual.GetVisualDescendents()
|
|
.OfType<Control>()
|
|
.TakeWhile(x => x.TemplatedParent != null)
|
|
.Where(x => x.TemplatedParent == control);
|
|
}
|
|
else
|
|
{
|
|
return Enumerable.Empty<Control>();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|