2010-08-16 93 views
1
<StackPanel Name="mypanel"> 
    <ScrollViewer Height="{Binding ElementName=mypanel, Path=ActualHeight}"> 

我需要,Height = mypanel.ActualHeight-60StackPanel中的ScrollViewer

我該怎麼辦?

編輯:

<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

發生了什麼事?

回答

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; 
    } 
} 
+0

哦,謝謝=^^ = – Kira 2010-08-16 11:12:24

+0

在XAML它會是這樣嗎? @ SciraViewer Height =「{Binding ElementName = mypanel,Path = ActualHeight,Converter = {StaticResource HeightAdjustmentConverter}}」 – Kira 2010-08-16 11:24:13

+0

@Kira是的,這是對的,用一行代碼實際創建靜態資源。 – 2010-08-16 11:25:35