获取所有子ListView的高度

时间:2016-02-29 08:42:25

标签: xaml listview win-universal-app windows-10-universal

所以我有一个带有 StackPanel ScrollView 。在StackPanel内部,我有三个ListViews ,具有不同的List<object>-sources

我想要实现的是禁用ListViews上的滚动,只在同一个ScrollView中滚动所有滚动。

当我对滚动视图的高度进行硬编码时,我得到了一些滚动的东西,但如果我不这样做,它只会在我释放手指后快速重新开始。如何才能达到高度?

当前XAML:

<Style x:Key="ListViewHeaderDisableScroll" TargetType="ListView">
                <Setter Property="ScrollViewer.VerticalScrollMode" Value="Disabled" />
                <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
                <Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="False" />
            </Style>

        <Page
        x:Class="TestApp.SecondaryView.PatientDetailView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ViewModels="using:TestApp.ViewModel"    
        mc:Ignorable="d">

        <Page.DataContext>
            <ViewModels:PatientDetailViewModel />
        </Page.DataContext>
        <Grid Background="White">
            <StackPanel Orientation="Vertical">
                /* Menu-Grid*/



                <ScrollViewer VerticalScrollMode="Enabled" VerticalScrollBarVisibility="Hidden" IsVerticalRailEnabled="True" Height="800">
                    <StackPanel Name="StackPanel_Lists">
                        <ListView Style="{StaticResource ListViewHeaderDisableScroll}" ItemsSource="{Binding DummyProblems}" Background="White">
                            <ListView.Header>
                            <StackPanel Style="{StaticResource ListViewHeaderStackPanel}">
                                <TextBlock Text="HEADER 1" FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"/>
                                <SymbolIcon Symbol="Play" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,0,10"/>
                            </StackPanel>
                        </ListView.Header>
                        <ListView.ItemTemplate>
                                <DataTemplate  x:DataType="ViewModels:PatientDetailViewModel">
                                    <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock FontSize="20" Grid.Row="0" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Note}"></TextBlock>
                                    <TextBlock FontSize="15" Grid.Row="1" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Fo}"></TextBlock>
                                </Grid>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                        </ListView>
                        <ListView Style="{StaticResource ListViewHeaderDisableScroll}" ItemsSource="{Binding DummyMeasures}"  Background="White">
                        <ListView.Header>
                            <StackPanel Background="DarkGray" Orientation="Horizontal" FlowDirection="LeftToRight" Padding="8,8,8,8">
                                <TextBlock Text="HEADER 2" FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"/>
                                <SymbolIcon Symbol="Play" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,0,10"/>
                            </StackPanel>
                        </ListView.Header>
                        <ListView.ItemTemplate>
                            <DataTemplate  x:DataType="ViewModels:PatientDetailViewModel">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <TextBlock FontSize="20" Grid.Row="0" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Description}"></TextBlock>
                                    <TextBlock FontSize="15" Grid.Row="1" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Note}"></TextBlock>
                                </Grid>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                        <ListView Style="{StaticResource ListViewHeaderDisableScroll}" ItemsSource="{Binding DummyGoals}"  Background="White">
                        <ListView.Header>
                            <StackPanel Background="DarkGray" Orientation="Horizontal" FlowDirection="LeftToRight" Padding="8,8,8,8">
                                <TextBlock Text="HEADER 3" FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"/>
                                <SymbolIcon Symbol="Play" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,0,10"/>
                            </StackPanel>
                        </ListView.Header>
                        <ListView.ItemTemplate>
                            <DataTemplate  x:DataType="ViewModels:PatientDetailViewModel">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <TextBlock FontSize="20" Grid.Row="0" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Description}"></TextBlock>
                                    <TextBlock FontSize="15" Grid.Row="1" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Fo}"></TextBlock>
                                </Grid>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                    </StackPanel>
                </ScrollViewer>
                </StackPanel>
        </Grid>

1 个答案:

答案 0 :(得分:0)

所以我发现了这个:

外面的StackPanel一切都毁了一切。我将其更改为Grid并制作了ScrollView *。现在一切正常