ListBox不显示纵向或横向模式下的所有项目

时间:2014-01-13 04:47:05

标签: windows-phone-7

我刚刚开始使用WP7。我想知道是否有更合适的方法来做到这一点,但是现在这似乎是最合乎逻辑的方法。我正在尝试显示包含相关电话代码的国家/地区列表,如下所示:

<Grid x:Name="ContentPanel" Grid.Row="0" Margin="12,0,12,0">
    <ScrollViewer Name="ScrollViewer" Height="3500">
        <StackPanel Name="StackPanel" Height="3500">
            <ListBox Name="codeList"  FontSize="26" SelectionChanged="codeList_SelectionChanged">
                <ListBoxItem Name="US">United States (+1)</ListBoxItem>
                <ListBoxItem Name="AG">Afghanistan (+93)</ListBoxItem>
                <ListBoxItem Name="AR">Argentina (+54)</ListBoxItem>
                <ListBoxItem Name="AU">Australia (+62)</ListBoxItem>
                <ListBoxItem Name="AS">Austria (+43)</ListBoxItem>
                <ListBoxItem Name="BE">Belgium (+32)</ListBoxItem>
                <ListBoxItem Name="BU">Bulgaria (+359)</ListBoxItem>
                <ListBoxItem Name="BR">Brazil (+55)</ListBoxItem>
                <ListBoxItem Name="CL">Chile (+56)</ListBoxItem>
                <ListBoxItem Name="CN">China (+86)</ListBoxItem>
                <ListBoxItem Name="CO">Colombia (+57)</ListBoxItem>
                <ListBoxItem Name="DK">Denmark (+45)</ListBoxItem>
                <ListBoxItem Name="EG">Egypt (+20)</ListBoxItem>
                <ListBoxItem Name="FR">France (+33  )</ListBoxItem>
                <ListBoxItem Name="DE">Germany (+49)</ListBoxItem>
                <ListBoxItem Name="GR">Greece (+30)</ListBoxItem>
                <ListBoxItem Name="HN">Hungary (+36)</ListBoxItem>
                <ListBoxItem Name="IN">India (+91)</ListBoxItem>
                <ListBoxItem Name="IT">Italy (+39)</ListBoxItem>
                <ListBoxItem Name="JP">Japan (+81)</ListBoxItem>
                <ListBoxItem Name="MX">Mexico (+52)</ListBoxItem>
                <ListBoxItem Name="ND">Netherlands (+31)</ListBoxItem>
                <ListBoxItem Name="NO">Norway (+47)</ListBoxItem>
                <ListBoxItem Name="PE">Peru (+51)</ListBoxItem>
                <ListBoxItem Name="PO">Poland (+48)</ListBoxItem>
                <ListBoxItem Name="PT">Portugal (+351)</ListBoxItem>
                <ListBoxItem Name="ES">Spain (+34)</ListBoxItem>
                <ListBoxItem Name="SE">Sweden (+46)</ListBoxItem>
                <ListBoxItem Name="SW">Switzerland (+41)</ListBoxItem>
                <ListBoxItem Name="TK">Turkey (+90)</ListBoxItem>
                <ListBoxItem Name="UR">Uruguay (+598)</ListBoxItem>
                <ListBoxItem Name="VE">Venezuela (+58)</ListBoxItem>
                <ListBoxItem Name="ZI">Zimbabwe (+263)</ListBoxItem>
            </ListBox>
        </StackPanel>
    </ScrollViewer>
</Grid>

事实证明,在肖像模式下,列表只显示到波兰,而希腊直到风景。无论我多少增加Scrollviewer和StackPanel大小。有什么建议吗?

2 个答案:

答案 0 :(得分:1)

在此布局中不需要StackPanel和ScrollViewer,因为ListBox会自行滚动所有内容。问题是您没有约束网格行的高度,这导致网格行中的项目占用尽可能多的高度。只需添加以下内容:

<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>

...在Grid标签下面,然后删除ScrollViewer和StackPanel标签,你应该好好去。

如果它不起作用,请告诉我,我会自己尝试一下。这只是我的头脑。

HTH!

答案 1 :(得分:0)

我同意AdvancedREI。

如果您使用的是默认项目模板,那么您已将网格设置为父级的顶行,其大小设置为auto:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

它给整个页面的列表框大小,限制它。因此,如果要在整个页面上设置列表框,请使用:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <ListBox Name="codeList"  FontSize="26">
                    <ListBoxItem Name="US">United States (+1)</ListBoxItem>
                    <ListBoxItem Name="AG">Afghanistan (+93)</ListBoxItem>
                    <ListBoxItem Name="AR">Argentina (+54)</ListBoxItem>
                    <ListBoxItem Name="AU">Australia (+62)</ListBoxItem>
                    <ListBoxItem Name="AS">Austria (+43)</ListBoxItem>
                    <ListBoxItem Name="BE">Belgium (+32)</ListBoxItem>
                    <ListBoxItem Name="BU">Bulgaria (+359)</ListBoxItem>
                    <ListBoxItem Name="BR">Brazil (+55)</ListBoxItem>
                    <ListBoxItem Name="CL">Chile (+56)</ListBoxItem>
                    <ListBoxItem Name="CN">China (+86)</ListBoxItem>
                    <ListBoxItem Name="CO">Colombia (+57)</ListBoxItem>
                    <ListBoxItem Name="DK">Denmark (+45)</ListBoxItem>
                    <ListBoxItem Name="EG">Egypt (+20)</ListBoxItem>
                    <ListBoxItem Name="FR">France (+33  )</ListBoxItem>
                    <ListBoxItem Name="DE">Germany (+49)</ListBoxItem>
                    <ListBoxItem Name="GR">Greece (+30)</ListBoxItem>
                    <ListBoxItem Name="HN">Hungary (+36)</ListBoxItem>
                    <ListBoxItem Name="IN">India (+91)</ListBoxItem>
                    <ListBoxItem Name="IT">Italy (+39)</ListBoxItem>
                    <ListBoxItem Name="JP">Japan (+81)</ListBoxItem>
                    <ListBoxItem Name="MX">Mexico (+52)</ListBoxItem>
                    <ListBoxItem Name="ND">Netherlands (+31)</ListBoxItem>
                    <ListBoxItem Name="NO">Norway (+47)</ListBoxItem>
                    <ListBoxItem Name="PE">Peru (+51)</ListBoxItem>
                    <ListBoxItem Name="PO">Poland (+48)</ListBoxItem>
                    <ListBoxItem Name="PT">Portugal (+351)</ListBoxItem>
                    <ListBoxItem Name="ES">Spain (+34)</ListBoxItem>
                    <ListBoxItem Name="SE">Sweden (+46)</ListBoxItem>
                    <ListBoxItem Name="SW">Switzerland (+41)</ListBoxItem>
                    <ListBoxItem Name="TK">Turkey (+90)</ListBoxItem>
                    <ListBoxItem Name="UR">Uruguay (+598)</ListBoxItem>
                    <ListBoxItem Name="VE">Venezuela (+58)</ListBoxItem>
                    <ListBoxItem Name="ZI">Zimbabwe (+263)</ListBoxItem>
                </ListBox>
    </Grid>
</Grid>

我看到你在国家/地区代码中忘记了拉脱维亚,我们也喜欢很棒的新应用=)