[英]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.