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);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
 /// <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;
Exemplo n.º 8
0
 public ResourceDictionary(IResourceHost owner)
     : this()
 {
     Owner = owner;
 }
Exemplo n.º 9
0
 void IResourceProvider.RemoveOwner(IResourceHost owner) => (Loaded as IResourceProvider)?.RemoveOwner(owner);
Exemplo n.º 10
0
 void IResourceProvider.AddOwner(IResourceHost owner) => (Loaded as IResourceProvider)?.AddOwner(owner);
Exemplo n.º 11
0
 public ThemeStyles(IResourceHost owner)
     : this()
 {
     Owner = owner;
 }
 public ResourceObservable(IResourceHost target, object key, Func <object?, object?>?converter)
 {
     _target    = target;
     _key       = key;
     _converter = converter;
 }