StackPanel 中的 ScrollViewer

发布于 2024-09-14 20:22:33 字数 762 浏览 6 评论 0原文

<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.ActualHeight 时,HeightAdjustmentConverter = 0

发生了什么?

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

I need, Height = mypanel.ActualHeight-60.

How can I do it?

EDIT:

<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 is working. When the Expander is, mypanel.ActualHeight, HeightAdjustmentConverter = 0.

What happened?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望喜 2024-09-21 20:22:34

您需要编写一个 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;
    }
}

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文