|
|
|
@ -8,8 +8,16 @@ using System.Reflection; |
|
|
|
|
|
|
|
namespace Perspex.Styling |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Extension methods for <see cref="Selector"/>.
|
|
|
|
/// </summary>
|
|
|
|
public static class Selectors |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Returns a selector which matches a previous selector's child.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="previous">The previous selector.</param>
|
|
|
|
/// <returns>The selector.</returns>
|
|
|
|
public static Selector Child(this Selector previous) |
|
|
|
{ |
|
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
@ -17,6 +25,12 @@ namespace Perspex.Styling |
|
|
|
return new Selector(previous, x => MatchChild(x, previous), " < ", stopTraversal: true); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a selector which matches a control's style class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="previous">The previous selector.</param>
|
|
|
|
/// <param name="name">The name of the style class.</param>
|
|
|
|
/// <returns>The selector.</returns>
|
|
|
|
public static Selector Class(this Selector previous, string name) |
|
|
|
{ |
|
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
@ -25,6 +39,11 @@ namespace Perspex.Styling |
|
|
|
return new Selector(previous, x => MatchClass(x, name), name[0] == ':' ? name : '.' + name); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a selector which matches a descendent of a previous selector.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="previous">The previous selector.</param>
|
|
|
|
/// <returns>The selector.</returns>
|
|
|
|
public static Selector Descendent(this Selector previous) |
|
|
|
{ |
|
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
@ -32,18 +51,36 @@ namespace Perspex.Styling |
|
|
|
return new Selector(previous, x => MatchDescendent(x, previous), " ", stopTraversal: true); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a selector which matches a type or a derived type.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="previous">The previous selector.</param>
|
|
|
|
/// <param name="type">The type.</param>
|
|
|
|
/// <returns>The selector.</returns>
|
|
|
|
public static Selector Is(this Selector previous, Type type) |
|
|
|
{ |
|
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
|
|
|
|
return new Selector(previous, x => MatchIs(x, type), type.Name); |
|
|
|
return new Selector(previous, x => MatchIs(x, type), type.Name, type); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a selector which matches a type or a derived type.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The type.</typeparam>
|
|
|
|
/// <param name="previous">The previous selector.</param>
|
|
|
|
/// <returns>The selector.</returns>
|
|
|
|
public static Selector Is<T>(this Selector previous) where T : IStyleable |
|
|
|
{ |
|
|
|
return previous.Is(typeof(T)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a selector which matches a control's Name.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="previous">The previous selector.</param>
|
|
|
|
/// <param name="name">The name.</param>
|
|
|
|
/// <returns>The selector.</returns>
|
|
|
|
public static Selector Name(this Selector previous, string name) |
|
|
|
{ |
|
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
@ -51,18 +88,38 @@ namespace Perspex.Styling |
|
|
|
return new Selector(previous, x => MatchName(x, name), '#' + name); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a selector which matches a type.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="previous">The previous selector.</param>
|
|
|
|
/// <param name="type">The type.</param>
|
|
|
|
/// <returns>The selector.</returns>
|
|
|
|
public static Selector OfType(this Selector previous, Type type) |
|
|
|
{ |
|
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
|
|
|
|
return new Selector(previous, x => MatchOfType(x, type), type.Name); |
|
|
|
return new Selector(previous, x => MatchOfType(x, type), type.Name, type); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a selector which matches a type.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The type.</typeparam>
|
|
|
|
/// <param name="previous">The previous selector.</param>
|
|
|
|
/// <returns>The selector.</returns>
|
|
|
|
public static Selector OfType<T>(this Selector previous) where T : IStyleable |
|
|
|
{ |
|
|
|
return previous.OfType(typeof(T)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a selector which matches a control with the specified property value.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The property type.</typeparam>
|
|
|
|
/// <param name="previous">The previous selector.</param>
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
/// <param name="value">The property value.</param>
|
|
|
|
/// <returns>The selector.</returns>
|
|
|
|
public static Selector PropertyEquals<T>(this Selector previous, PerspexProperty<T> property, object value) |
|
|
|
{ |
|
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
@ -71,6 +128,11 @@ namespace Perspex.Styling |
|
|
|
return new Selector(previous, x => MatchPropertyEquals(x, property, value), $"[{property.Name}={value}]"); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a selector which enters a lookless control's template.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="previous">The previous selector.</param>
|
|
|
|
/// <returns>The selector.</returns>
|
|
|
|
public static Selector Template(this Selector previous) |
|
|
|
{ |
|
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
|