public override object ProvideValue(IServiceProvider serviceProvider)
        {
            Style result = new Style();

            foreach (var styleKey in m_stylesKeys)
            {
                Style style = (Style)new StaticResourceExtension(styleKey).ProvideValue(serviceProvider);

                if (style == null) new ArgumentException(styleKey + " not found");

                result.Merge(style);
            }

            return result;
        }
Exemplo n.º 2
0
 /// <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>
 public override object ProvideValue(IServiceProvider serviceProvider)
 {
     Style resultStyle = new Style();
     foreach(string currentResourceKey in resourceKeys) {
         object key = currentResourceKey;
         if(currentResourceKey == ".") {
             IProvideValueTarget service = (IProvideValueTarget)serviceProvider.GetService(typeof(IProvideValueTarget));
             key = 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;
 }