【问题标题】:how to display complete data in a listbox in windows phone 7 application如何在 Windows Phone 7 应用程序的列表框中显示完整数据
【发布时间】:2014-03-10 09:24:57
【问题描述】:

我正在为 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>

注释部分是按钮,使用时我可以导航,但不使用按钮也可以导航

【问题讨论】:

  • Width="800" 是问题所在。

标签: c# xaml windows-phone-7 listbox


【解决方案1】:

我认为你的结构看起来有点复杂:下面的代码可以工作吗?

<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);
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多