Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Markup extensions at design time not working

$
0
0
  public class DPIAdjustedDouble: global::System.Windows.Markup.MarkupExtension
  {
    public double value { get; set; }

    private static double _factor = 0;

    public DPIAdjustedDouble()
    {
        _factor = 1;
    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
      return value / _factor;
    }

  }
<cmn:DPIAdjustedDouble value="24" x:Key="DefaultButtonFontSize"></cmn:DPIAdjustedDouble><Style TargetType="{x:Type Button}"><Setter Property="FontSize" Value="{StaticResource DefaultButtonFontSize}" /></Style>

This code does work at runtime, but at design time I get following errors:

  • System.Windows.Markup.XamlParseException
    'DPIAdjustedDouble' is not valid for Setter.Value. The only supported MarkupExtension types are DynamicResourceExtension and BindingBase or derived types.
  • An object of the type "DPIAdjustedDouble" cannot be applied to a property that expects the type "System.Double".

I'm trying to adapt font sizes and other properties to different system font sizes. Originally they were defined as:

<sys:Double value="24" x:Key="DefaultButtonFontSize"></sys:Double>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>