Kelary.Infrastructure/Markup/MultiStyleExtension.cs
/// <summary>
/// Returns a style that merges all styles with the keys specified in the constructor.
/// </summary>
/// <param name="serviceProvider">The service provider for this markup extension.</param>
/// <returns>A style that merges all styles with the keys specified in the constructor.</returns>
Returns a style that merges all styles with the keys specified in the constructor.
Returns a style that merges all styles with the keys specified in the constructor .
public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(new DependencyObject()))
                return null;
            Style resultStyle = new Style();
            foreach (string currentResourceKey in resourceKeys)
            {
                object key = currentResourceKey;
                if (currentResourceKey == ".")
                {
                    var service = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));
                    key = (service.TargetObject is Style)
                        ? ((Style)service.TargetObject).TargetType
                        : service.TargetObject.GetType();
                }
                Style currentStyle = new StaticResourceExtension(key).ProvideValue(serviceProvider) as Style;
                if (currentStyle == null)
                    throw new InvalidOperationException("Could not find style with resource key " + currentResourceKey + ".");
                resultStyle.Merge(currentStyle);
            }
            return resultStyle;
        }
public override object ProvideValue ( IServiceProvider serviceProvider ) { if ( System . ComponentModel . DesignerProperties . GetIsInDesignMode ( new DependencyObject ( ) ) ) return null ; Style resultStyle = new Style ( ) ; foreach ( string currentResourceKey in resourceKeys ) { object key = currentResourceKey ; if ( currentResourceKey == " " ) { var service = ( IProvideValueTarget ) serviceProvider . GetService ( typeof ( IProvideValueTarget ) ) ; key = ( service . TargetObject is Style ) ? ( ( Style ) service . TargetObject ) . TargetType : service . TargetObject . GetType ( ) ; } Style currentStyle = new StaticResourceExtension ( key ) . ProvideValue ( serviceProvider ) as Style ; if ( currentStyle == null ) throw new InvalidOperationException ( " " + currentResourceKey + " " ) ; resultStyle . Merge ( currentStyle ) ; } return resultStyle ; }
Returns a style that merges all styles with the keys specified in the constructor.
Returns a style that merges all styles with the keys specified in the constructor .
// Styles could not be found in design-time. // So if in design-mode return null
A style that merges all styles with the keys specified in the constructor.
A style that merges all styles with the keys specified in the constructor .
serviceProvider
IServiceProvider
The service provider for this markup extension.
The service provider for this markup extension .