如何设置WPFExtensions.ZoomControl默认缩放

时间:2011-06-23 17:20:57

标签: wpf

有人知道如何在wpfextensions中包含的ZoomControl中将默认缩放级别设置为1:1吗?项目首次启动时,默认行为是缩放以填充。

我试过了两次

 <zoom:ZoomControl Mode="Original">

 <zoom:ZoomControl Zoom="1">

两者都不起作用......

1 个答案:

答案 0 :(得分:5)

看起来您必须将Mode属性设置为Original,或者您可以在ZoomControl的Loaded事件处理程序中显式调用ZoomToOriginal

似乎EqualityToBooleanConverter会抛出异常,而不应该抛出异常。代码如下:

public class EqualityToBooleanConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return object.Equals(value, parameter);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if ((bool)value)
            return parameter;

        //it's false, so don't bind it back
        throw new Exception("EqualityToBooleanConverter: It's false, I won't bind back.");
    }
}

您需要删除该例外,然后返回Binding.DoNothing

该转换器用于ZoomControl的控件模板,如下所示:

<RadioButton Content="1:1"
    GroupName="rbgZoomMode"
    IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Mode,Converter={StaticResource equalityConverter},ConverterParameter={x:Static Controls:ZoomControlModes.Original}}" />
<RadioButton Content="Fill"
    GroupName="rbgZoomMode"
    IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Mode,Converter={StaticResource equalityConverter},ConverterParameter={x:Static Controls:ZoomControlModes.Fill}}" />

如此有效,如果值为true,它只会尝试绑定回源。但正如你所见,它引发了一个例外。