我有一个将与一些数据绑定的透视控件:
[编辑]这是我完整的xaml,我试着放了Grid.行的定义,但仍然不起作用。
<phone:PhoneApplicationPage x:Class="Horoscopo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait"
Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--Data context is set to sample data above and LayoutRoot contains the root grid where all other page content is placed-->
<Grid x:Name="LayoutRoot">
<Grid.Background>
<ImageBrush Stretch="None"
ImageSource="/Assets/bg.jpg"
AlignmentY="Top"
AlignmentX="Center" />
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<phone:Pivot>
<phone:Pivot.Title>
<TextBlock Text="virgo"
Style="{StaticResource PhoneTextNormalStyle}"
Foreground="White"></TextBlock>
</phone:Pivot.Title>
<phone:PivotItem >
<phone:PivotItem.Header>
<TextBlock Text="hoje"
Margin="9,-7,0,0"
Style="{StaticResource PhoneTextTitle1Style}">
<TextBlock.Foreground>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="Black"
Offset="0" />
<GradientStop Color="#FFE9FF0B"
Offset="1" />
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
</phone:PivotItem.Header>
<!--ContentPanel contains LongListSelector and LongListSelector ItemTemplate. Place additional content here-->
<ScrollViewer Grid.Row="1"
Margin="12,0,12,0">
<Grid x:Name="ContentPanel">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<phone:LongListSelector x:Name="MainLongListSelector"
Margin="0,0,-12,0"
ItemsSource="{Binding Items}"
SelectionChanged="MainLongListSelector_SelectionChanged">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17">
<TextBlock Text="{Binding LineOne}"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}">
<TextBlock.Foreground>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="Black"
Offset="0" />
<GradientStop Color="#FFE9FF0B"
Offset="1" />
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
<TextBlock x:Name="txtTexto"
Text="{Binding LineTwo}"
TextWrapping="Wrap"
Margin="12,-6,12,0"
Style="{StaticResource PhoneTextSubtleStyle}"
Foreground="White" />
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
</ScrollViewer>
</phone:PivotItem>
<phone:PivotItem>
<phone:PivotItem.Header>
<TextBlock Text="favorito"
Margin="9,-7,0,0"
Style="{StaticResource PhoneTextTitle1Style}">
<TextBlock.Foreground>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="Black"
Offset="0" />
<GradientStop Color="#FFE9FF0B"
Offset="1" />
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
</phone:PivotItem.Header>
<!--ContentPanel contains LongListSelector and LongListSelector ItemTemplate. Place additional content here-->
<ScrollViewer Grid.Row="1"
Margin="12,0,12,0">
<Grid x:Name="ContentFavoritoPanel">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<phone:LongListSelector x:Name="FavoritoListSelector"
Margin="0,0,-12,0"
ItemsSource="{Binding Favoritos}"
SelectionChanged="MainLongListSelector_SelectionChanged">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17">
<TextBlock Text="{Binding LineOne}"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}">
<TextBlock.Foreground>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="Black"
Offset="0" />
<GradientStop Color="#FFE9FF0B"
Offset="1" />
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
<TextBlock x:Name="txtTexto"
Text="{Binding LineTwo}"
TextWrapping="Wrap"
Margin="12,-6,12,0"
Style="{StaticResource PhoneTextSubtleStyle}"
Foreground="White" />
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
</ScrollViewer>
</phone:PivotItem>
</phone:Pivot>
</Grid>
但是滚动查看器不起作用,我不知道为什么会发生这种情况。
我尝试了这个线程的建议,但没有奏效。有人能帮我吗?
谢谢。
尝试在网格内容面板下添加以下代码:
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
事实上,正如我测试的那样,您的代码运行良好。
如果您需要进一步的帮助,您可能需要粘贴整个xaml。
我在数据透视项中使用ScrollViewer时遇到了类似的问题。问题是ScrollViewer中的内容(网格)与数据透视项的高度相同,因此ScrollViewer实际上没有任何可滚动的内容。我通过使数据透视项的高度小于ScrollViewer中内容的高度来解决这个问题。
问题是由于使用了多个ScrollViewer;当LongListSelector中的项目超过控件的大小时,它有默认的滚动机制,所以我们不需要显式地在LongListSelecter上放置ScrollViewer。
在您的情况下,将有两个滚动查看器,一个来自LongListSelector,另一个是您显式放置的。所以滚动不会发生。
因此,只需从所有PivotItems中删除ScrollViewer,并将Grid.Row属性设置为LongListSelector。