我发现了错误,因此这里的代码对缩放文本感兴趣。
首先是ValueConverter和MarkupExtension,它是传递double作为参数所必需的。
public class ScaleValueConverter : IValueConverter
{
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
{
double v = (double) value * (double) parameter;
return v;
}
public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public sealed class DoubleExtension : MarkupExtension
{
public DoubleExtension (double value) { this.Value = value; }
public double Value { get; set; }
public override Object ProvideValue (IServiceProvider sp) { return Value; }
};
现在是XAML:
<TextBlock DockPanel.Dock="Top"
FontSize="{Binding Path=FontSize,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window},
Converter={StaticResource ScaleValueConverter},
ConverterParameter={local:Int32 2}}"
>Some Text</TextBlock>
这样就可以通过调整Window的FontSize来缩放所有字体。所有其他字体大小都是相对的,取决于它。