0

我看到了其他处理网格并建议“2 *”的答案,但这个表达式在这种情况下不起作用。任何想法?

4

1 回答 1

3

绑定到 window.ActualHeight,并使用转换器(DivideByTwoConverter,或者更通用的东西,例如带参数的 MultiplicationConverter)

public class DoubleMultiplyConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (!(value is double)) return null;

        double multiplier = 1;
        double.TryParse(parameter as string, out multiplier);
        return ((double)value) * multiplier;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        // Not needed
        return null;
    }
}

XAML:

<Window x:Name="window">
 <Popup Height="{Binding ActualHeight, ElementName=window, Converter=...}" />
</Window>
于 2013-10-11T15:36:19.913 回答