<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.ActualHeight
,HeightAdjustmentConverter = 0
。
发生了什么事?
答案 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;
}
}