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

I am building an application for windows phone 7 where i have a listbox in which i am displaying data from webservice. I want to show a complete data in my listbox. I am using the textwrapping to Wrap but still it is not showing the data. The data which exceeds the screen is not displayed. Moreover i want that if someone clicks the item in the listbox it is navigated to a new page. I am able to do it using Button in listbox but i donot want to use button. Please have a look at my xaml and try to solve both my issue.

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>

The comment part is the button which when used i am able to navigate but will it possible to navigate without using button

Answers


Your structure looks a bit more complicated for what it needs to be I think: would the code below work?

<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>

Assuming you have

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

Your code behind

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

Need Your Help

Save dynamically data to localStorage and load this data in a html table when .html loads

javascript html-table

I got this project for school, I need to load data from sessionStorage in a html table when my .html loads (not only from cache).

Laravel routing groups

laravel routing middleware prefix

I have a question about routing groups. I have two types of users and I can not use the role system. Following the laracast email verification video I was able to get a new type of user to work. ...