我正在使用Xaml编写UWP应用程序 我尝试将列表视图放在我有attandence列表但我看不到滚动ba。我还在所有页面上都有scrollView,以便用户最小化页面,所以如果我在列表中有一个很长的时间,我可以向下滚动所有页面以查看注意力中的项目,但我只想滚动在列表视图内,而不是所有页面。 我尝试了许多diffrenet事情坚果没有任何作用 这是我的Xaml代码:
<Grid Width="600" Visibility="{Binding EventVisible}" ScrollViewer.HorizontalScrollMode="Auto">
<StackPanel>
<ListView VerticalAlignment="Top" x:Name="GuestsList" ItemsSource="{Binding Guests, Mode=TwoWay}" >
<ListView.ItemTemplate>
<DataTemplate>
<Border BorderBrush="{StaticResource SystemControlBackgroundBaseLowBrush}" BorderThickness="0,0,0,2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text="{Binding CustomId, Mode=TwoWay}" Grid.Row="0" Grid.Column="0"/>
<Button Command="{Binding ElementName=GuestsList, Path=DataContext.UpdateGuestCommand}" CommandParameter="{Binding}" Grid.Row="0" Grid.Column="1" >
<SymbolIcon Symbol="Edit"></SymbolIcon>
</Button>
<Button Command="{Binding ElementName=GuestsList, Path=DataContext.RemoveGuestCommand}" CommandParameter="{Binding}" Grid.Row="0" Grid.Column="2">
<SymbolIcon Symbol="Delete"></SymbolIcon>
</Button>
</Grid>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</Grid>
答案 0 :(得分:0)
您的DataTemplate项目是一个内置网格的边框。这些控件都不会提供ScrollViewer,因此您无法在ListView项目中滚动。尝试这样的事情:
<Grid Width="600" Visibility="{Binding EventVisible}" ScrollViewer.HorizontalScrollMode="Auto">
<StackPanel>
<ListView VerticalAlignment="Top" x:Name="GuestsList" ItemsSource="{Binding Guests, Mode=TwoWay}" >
<ListView.ItemTemplate>
<DataTemplate>
<Border BorderBrush="{StaticResource SystemControlBackgroundBaseLowBrush}" BorderThickness="0,0,0,2">
<GridView>
<Grid Name="FirstRow">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Text="{Binding CustomId, Mode=TwoWay}" Grid.Column="0"/>
<Button Command="{Binding ElementName=GuestsList, Path=DataContext.UpdateGuestCommand}" CommandParameter="{Binding}" Grid.Column="1" >
<SymbolIcon Symbol="Edit"></SymbolIcon>
</Button>
<Button Command="{Binding ElementName=GuestsList, Path=DataContext.RemoveGuestCommand}" CommandParameter="{Binding}" Grid.Column="2">
<SymbolIcon Symbol="Delete"></SymbolIcon>
</Button>
</Grid>
</GridView>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</Grid>
答案 1 :(得分:0)
我能够通过附加行为来规避滚动行为。
有关更多详细信息,请参见https://stackoverflow.com/a/7003338/7025289。
xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
xmlns:behaviors="clr-namespace:TestProject.Management.Behaviors"
<ListView ItemsSource="{Binding Path=SomeData}">
<b:Interaction.Behaviors>
<behaviors:IgnoreMouseWheelBehavior />
</b:Interaction.Behaviors>
</ListView>