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>