StackPanel中的ScrollViewer

时间:2010-08-16 11:04:06

标签: c# wpf scrollviewer stackpanel

<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时,一切正常。当Expandermypanel.ActualHeightHeightAdjustmentConverter = 0

发生了什么事?

1 个答案:

答案 0 :(得分: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;
    }
}