views:

45

answers:

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

I need, that Height = mypanel.ActualHeight-60. How to do it?

A: 

You need to write an IValueConverter that takes in the ActualHeight and returns a new value of that minus 60.

Something like:

[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;
    }
}
Martin Harris
oh, thanks =^.^=
Kira
In XAML it will be like this?<ScrollViewer Height="{Binding ElementName=mypanel, Path=ActualHeight, Converter={StaticResource HeightAdjustmentConverter}}"
Kira
@Kira Yep, that would be right, with a line somewhere to actually create the static resource.
Martin Harris
A: 
<StackPanel Name="mypanel">
        <ContentControl Content="{Binding HeaderPart}" /> <= here must be Expander
        <ScrollViewer Height="{Binding ElementName=mypanel, Path=ActualHeight, Converter={StaticResource HeightConverter}}" >
            <StackPanel>
            </StackPanel>
        </ScrollViewer>

When There is no Expander, all are working. When Expander is, mypanel.ActualHeight in HeightAdjustmentConverter = 0

What happend?

Kira