繁体   English   中英

如何在Windows Phone 7应用程序的列表框中显示完整数据

[英]how to display complete data in a listbox in windows phone 7 application

我正在为Windows Phone 7构建一个应用程序,其中有一个列表框,其中显示了来自Web服务的数据。 我想在列表框中显示完整的数据。 我正在使用textwrapping进行包装,但仍未显示数据。 超出屏幕的数据不会显示。 此外,我希望如果有人单击列表框中的项目,则将其导航到新页面。 我可以使用列表框中的按钮来做到这一点,但我不想使用按钮。 请看看我的xaml并尝试解决我的问题。

XAML:

<ListBox Name="CityList" BorderThickness="0" 
         Height="650" VerticalAlignment="Bottom" 
         SelectionChanged="CityList_SelectionChanged" Foreground="Black" 
         Background="AntiqueWhite" Grid.Row="1">

<ListBox.ItemTemplate>
 <DataTemplate>
  <!--<Button IsHitTestVisible="False" BorderThickness="0">
      <Button.Content>-->

 <ScrollViewer HorizontalScrollBarVisibility="Disabled"
               VerticalScrollBarVisibility="Disabled"
               Height="80" Width="800">

 <StackPanel Orientation="Horizontal" 
             Margin="0,0,10,10"
             Background="AntiqueWhite" 
             Width="2000">

 <Image Source="{Binding ImageBind }" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" 
        Margin="0,0,20,10" Height="100" 
        Width="145" />

 <StackPanel Orientation="Vertical">
    <StackPanel Orientation="Horizontal">

 <TextBlock Text="{Binding city_name}"
            Foreground="Red" 
            FontFamily="Verdana" />

 <TextBlock Text=", " Foreground="Red" FontFamily="Verdana" />
 <TextBlock Text="{Binding state}" Foreground="Red" 
            FontFamily="Verdana" />

 </StackPanel>

 <TextBlock Text="{Binding Path=city_description}" 
 TextWrapping="Wrap" Foreground="Black" FontFamily="Verdana" Margin="10,0,10,10">
 </TextBlock>

 </StackPanel>
    </StackPanel>
 </ScrollViewer>

 <!--</Button.Content>
     </Button>-->

</DataTemplate>
  </ListBox.ItemTemplate>

</ListBox>

评论部分是按钮,使用该按钮我可以导航,但不用按钮也可以导航

我认为您的结构看起来有点复杂:下面的代码行得通吗?

<ListBox Name="CityList" BorderThickness="0" 
             Height="600" VerticalAlignment="Bottom" 

              Foreground="Black" 
              Background="AntiqueWhite" Grid.Row="1">

            <ListBox.ItemTemplate>
                <DataTemplate>
                    <!--      <Button IsHitTestVisible="False" BorderThickness="0">
        <Button.Content>-->

                    <Grid Tap="ShowState">

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="200" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <Image Grid.Column="0" Source="http://static.bbci.co.uk/frameworks/barlesque/2.60.3/orb/4/img/bbc-blocks-dark.png" 
                           HorizontalAlignment="Stretch" 
                           VerticalAlignment="Stretch" 
                           Margin="0,0,20,10" Height="100" Width="145" />
                        <StackPanel Grid.Column="2">
                            <TextBlock Text="{Binding city_name}"
                                       Foreground="Red" 
                                       FontFamily="Verdana" TextWrapping="Wrap" />

                            <TextBlock Text=", " Foreground="Red" FontFamily="Verdana" />
                            <TextBlock Text="{Binding state}" Foreground="Red" TextWrapping="Wrap"
                          FontFamily="Verdana" />

                            <TextBlock Text="{Binding city_description}" 
                                   TextWrapping="Wrap" Foreground="Black" FontFamily="Verdana" Margin="10,0,10,10" />
                        </StackPanel>
                    </Grid>


                </DataTemplate>
            </ListBox.ItemTemplate>

        </ListBox>

假设你有

public class CityListData
{
    public string city_name { get; set; }
    public string state { get; set; }
    public string city_description { get; set; }
}

您的代码背后

private void ShowState(object sender, GestureEventArgs e)
    {
        var control = sender as Grid;

        if (control != null)
        {
            var entity = (CityListData) control.DataContext;
            MessageBox.Show("You clicked on the state " + entity.city_name);
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM