public static IObservable <object?> GetResourceObservable( this IResourceHost control, object key, Func <object?, object?>?converter = null) { control = control ?? throw new ArgumentNullException(nameof(control)); key = key ?? throw new ArgumentNullException(nameof(key)); return(new ResourceObservable(control, key, converter)); }
public static object?FindResource(this IResourceHost control, object key) { control = control ?? throw new ArgumentNullException(nameof(control)); key = key ?? throw new ArgumentNullException(nameof(key)); if (control.TryFindResource(key, out var value)) { return(value); } return(AvaloniaProperty.UnsetValue); }
public static bool TryFindResource(this IResourceHost control, object key, out object?value) { control = control ?? throw new ArgumentNullException(nameof(control)); key = key ?? throw new ArgumentNullException(nameof(key)); IResourceNode?current = control; while (current != null) { if (current.TryGetResource(key, out value)) { return(true); } current = (current as IStyledElement)?.StylingParent as IResourceNode; } value = null; return(false); }
/// <summary> /// Looks for a suitable resource in the program. /// </summary> /// <param name="key">Resource name</param> /// <typeparam name="T">Resource type</typeparam> /// <returns>Resource found, otherwise null</returns> public static T GetResource <T>(object key) { object value = null; IResourceHost current = Current; while (current != null) { if (current is IResourceHost host) { if (host.TryGetResource(key, out value)) { return((T)value); } } current = ((IStyledElement)current).StylingParent as IResourceHost; } return((T)value); }
/// <summary> /// Initializes a new instance of the <see cref="ResourceDictionary"/> class. /// </summary> public ResourceDictionary(IResourceHost owner) => Owner = owner;
public void RemoveOwner(IResourceHost owner) => Owner = null;
public void AddOwner(IResourceHost owner) => Owner = owner;
public ResourceDictionary(IResourceHost owner) : this() { Owner = owner; }
void IResourceProvider.RemoveOwner(IResourceHost owner) => (Loaded as IResourceProvider)?.RemoveOwner(owner);
void IResourceProvider.AddOwner(IResourceHost owner) => (Loaded as IResourceProvider)?.AddOwner(owner);
public ThemeStyles(IResourceHost owner) : this() { Owner = owner; }
public ResourceObservable(IResourceHost target, object key, Func <object?, object?>?converter) { _target = target; _key = key; _converter = converter; }