【问题标题】:ScrollViewer in StackPanelStackPanel 中的 ScrollViewer
【发布时间】:2013-08-05 07:42:34
【问题描述】:
<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.ActualHeightHeightAdjustmentConverter = 0

发生了什么?

【问题讨论】:

    标签: c# wpf scrollviewer stackpanel


    【解决方案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;
        }
    }
    

    【讨论】:

    • 在 XAML 中会是这样吗?
    • @Kira 是的,没错,在某处有一行来实际创建静态资源。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多