1
<StackPanel Name="mypanel">
   <ScrollViewer Height="{Binding ElementName=mypanel, Path=ActualHeight}">

我需要,Height = mypanel.ActualHeight-60

我该怎么做?

编辑:

<StackPanel Name="mypanel">
    <ContentControl Content="{Binding HeaderPart}" /> <= here must be Expander
    <ScrollViewer Height="{Binding ElementName=mypanel, Path=ActualHeight, Converter={StaticResource HeightConverter}}" >
        <StackPanel>
        </StackPanel>
    </ScrollViewer>

当没有Expander时,一切正常。当Expander是,mypanel.ActualHeightHeightAdjustmentConverter = 0

发生了什么?

4

1 回答 1

1

您需要编写一个IValueConverter接受ActualHeight并返回负 60 的新值。

就像是:

[ValueConversion(typeof(double), typeof(double))]
public class HeightAdjustmentConverter: IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        double original = (double)value;
        return double - 60;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        double adjusted = (double)value;
        return adjusted + 60;
    }
}
于 2010-08-16T11:10:04.557 回答