【发布时间】:2014-05-31 08:38:51
【问题描述】:
我是 Windows Phone 8 的新手。我想在列表框中同时显示图像和文本。我使用流动代码来做到这一点,但它在我的设计视图中没有显示任何内容。然后我调试这段代码,它除了页面标题什么都没有显示。请帮我 。
<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:UI="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI"
x:Class="Masala.Infotainment"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="images/home_bg.png"/>
</Grid.Background>
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="Page Title"></TextBlock>
</StackPanel>
<Grid Grid.Row="1">
<ListBox Name="mahin" Width="450">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Margin="8"
VerticalAlignment="Top"
Source="images/cc.png"
Width="100"
Height="100" />
<StackPanel>
<TextBlock Text="MAHIN"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
【问题讨论】:
-
你忘了设置
ListBox的ItemSource吧? -
你试过用
Grid代替StackPanel吗?