Xaml 在Windows phone中设置列表框高度

Xaml 在Windows phone中设置列表框高度,xaml,windows-phone-8,windows-phone,Xaml,Windows Phone 8,Windows Phone,如何在纵向或横向视图中为列表框自动设置合适的大小 我在纵向视图中没有任何问题: 但在横向视图中,列表框的高度不正常,并且列表框不必位于记录面板上。 这是我的xaml代码: <Grid x:Name="LayoutRoot"> <Grid.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop

如何在纵向或横向视图中为列表框自动设置合适的大小

我在纵向视图中没有任何问题:

但在横向视图中,列表框的高度不正常,并且列表框不必位于记录面板上。

这是我的xaml代码:

<Grid x:Name="LayoutRoot">
    <Grid.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#E9E9E9" Offset="0"/>
            <GradientStop Color="#FEFEFE" Offset="1"/>
        </LinearGradientBrush>
    </Grid.Background>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <MediaElement Name="SoundPlayer" AutoPlay="False" Volume="1" />

    <StackPanel Grid.Row="0">

        <StackPanel x:Name="StackPanelTopBar" >
        </StackPanel>

        <phone:Pivot  Height="40" Background="#F9A11D" SelectionChanged="Pivot_SelectionChanged" >
            <phone:Pivot.HeaderTemplate>
                <DataTemplate>
                    <TextBlock FontSize="24" Text="{Binding}" Margin="0,-5,0,0"/>
                </DataTemplate>
            </phone:Pivot.HeaderTemplate>
            <phone:PivotItem Header="Alle"/>
            <phone:PivotItem Header="A-E"/>
            <phone:PivotItem Header="F-J"/>
            <phone:PivotItem Header="K-O"/>
            <phone:PivotItem Header="P-T"/>
            <phone:PivotItem Header="U-Z"/>
        </phone:Pivot>

        <ListBox x:Name="ListBoxAlphabet" Height="Auto">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <controls:RoundButton Tag="{Binding File}" Content="{Binding Label}" FontSize="30"  ButtonHeight="90" ButtonWidth="90"
                            HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5" Background="#FFD0D2D3" Foreground="White" PressedBrush="#F9A11D" BorderBrush="{StaticResource TransparentBrush}" Click="RoundButtonAlphabet_Click" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

    </StackPanel>

    <Grid x:Name="RecordPanel" Grid.Row="1" Margin="0,0,0,8">
        <StackPanel VerticalAlignment="Bottom" Height="100">
            <userControls:SoundRecorderPanel></userControls:SoundRecorderPanel>
        </StackPanel>
    </Grid>
</Grid>


我不知道我是否理解正确,但是如果您希望记录面板位于字母表上并且字母表列表可滚动,那么我可以帮助您

字母列表框位于记录面板上的原因是您将列表框放置在堆栈面板上。stackpanel位于网格行上,其“高度”属性为“自动”。如果希望记录面板位于字母表上,则应如下定义行定义:

<Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <StackPanel x:Name="StackPanelTopBar" Grid.Row="0" >
        </StackPanel>

        <phone:Pivot  Height="80" Background="#F9A11D" Grid.Row="1" SelectionChanged="Pivot_SelectionChanged">
            <phone:Pivot.HeaderTemplate>
                <DataTemplate>
                    <TextBlock FontSize="24" Text="{Binding}" Margin="0,-5,0,0"/>
                </DataTemplate>
            </phone:Pivot.HeaderTemplate>
            <phone:PivotItem Header="Alle"/>
            <phone:PivotItem Header="A-E"/>
            <phone:PivotItem Header="F-J"/>
            <phone:PivotItem Header="K-O"/>
            <phone:PivotItem Header="P-T"/>
            <phone:PivotItem Header="U-Z"/>
        </phone:Pivot>

        <ListBox x:Name="ListBoxAlphabet" Height="Auto" Grid.Row="2">
        // and so on...

当然,listbox不适合屏幕,如果您想查看所有字母表,必须滚动列表

编辑:您还必须将列表框和轴所在的stackpanel更改为网格,如下所示:

<Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <StackPanel x:Name="StackPanelTopBar" Grid.Row="0" >
        </StackPanel>

        <phone:Pivot  Height="80" Background="#F9A11D" Grid.Row="1" SelectionChanged="Pivot_SelectionChanged">
            <phone:Pivot.HeaderTemplate>
                <DataTemplate>
                    <TextBlock FontSize="24" Text="{Binding}" Margin="0,-5,0,0"/>
                </DataTemplate>
            </phone:Pivot.HeaderTemplate>
            <phone:PivotItem Header="Alle"/>
            <phone:PivotItem Header="A-E"/>
            <phone:PivotItem Header="F-J"/>
            <phone:PivotItem Header="K-O"/>
            <phone:PivotItem Header="P-T"/>
            <phone:PivotItem Header="U-Z"/>
        </phone:Pivot>

        <ListBox x:Name="ListBoxAlphabet" Height="Auto" Grid.Row="2">
        // and so on...

//等等。。。

希望这有帮助

非常感谢你的帮助。在您的帮助下,我的问题得到了解决。我认为制作[应用程序端菜单][1][1]: