列表框项目是可点击的,但不可见WP7

时间:2014-04-12 20:11:28

标签: windows-phone-7 listbox visible clickable

我正在制作Windows Phone 7应用程序 我将字符串项添加到ListBox中 当我运行应用程序时,ListBox中的项目是可点击的,但我实际上看不到它们 它们设置为可见和白色(黑色背景)。

有谁知道可能导致这种情况的原因?

这是我的ListBox代码:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0" ShowGridLines="False">
        <StackPanel>
            <StackPanel Orientation="Horizontal">
                <Button Content="i" Height="72" HorizontalAlignment="Left" Margin="0,0,0,0" Name="informationButton" VerticalAlignment="Top" Width="70" FontFamily="Georgia" DataContext="{Binding}" Click="informationButton_Click" />
                <TextBox Height="72" HorizontalAlignment="Left" Margin="-10,0,0,0" Name="searchBox1" Text="Search..." VerticalAlignment="Top" Width="336" TextChanged="searchBox1_TextChanged" />
                <Button Content="→" Height="72" HorizontalAlignment="Right" Margin="-15,0,0,0" Name="searchButton" VerticalAlignment="Top" Width="74" Click="button1_Click_1"  />                
            </StackPanel>
            <ListBox Height="533" Name="listBox" Width="452" ScrollViewer.VerticalScrollBarVisibility="Visible" DoubleTap="textBlock_DoubleTap" SelectionChanged="listBox_SelectionChanged" Padding="2,5">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Height="30" Text="" Margin="2,10" Name="textBlock1" DoubleTap="TextBlock_DoubleTap" Visibility="Visible"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>
    </Grid>

这是添加项目的XAML。字符串部分有效。

try
{
    if (root2.getSOCSectionListByNbrResponse.ClassOffered.ClassNumber != null) 
        text = text + root2.getSOCSectionListByNbrResponse.ClassOffered.ClassNumber;
    if (root2.getSOCSectionListByNbrResponse.ClassOffered.SectionNumber != null) 
        text = text + "   " + root2.getSOCSectionListByNbrResponse.ClassOffered.SectionNumber;
    if (root2.getSOCSectionListByNbrResponse.ClassOffered.CourseDescr != null) 
        text = text + "   " + root2.getSOCSectionListByNbrResponse.ClassOffered.CourseDescr;
    if (root2.getSOCSectionListByNbrResponse.ClassOffered.SectionTypeDescr != null) 
        text = text + "   " + root2.getSOCSectionListByNbrResponse.ClassOffered.SectionTypeDescr;
    if (root2.getSOCSectionListByNbrResponse.ClassOffered.Meeting.Days != null) 
        text = text + "   " + root2.getSOCSectionListByNbrResponse.ClassOffered.Meeting.Days;
    if (root2.getSOCSectionListByNbrResponse.ClassOffered.Meeting.Times != null) 
        text = text + "   " + root2.getSOCSectionListByNbrResponse.ClassOffered.Meeting.Times;
    if (root2.getSOCSectionListByNbrResponse.ClassOffered.Instructor.InstructorName != null) 
        text = text + "   " + root2.getSOCSectionListByNbrResponse.ClassOffered.Instructor.InstructorName;
    if (root2.getSOCSectionListByNbrResponse.ClassOffered.EnrollmentStatus != null) 
        text = text + "   " + root2.getSOCSectionListByNbrResponse.ClassOffered.EnrollmentStatus;
}
catch (Exception e)
{

}

listBox.Items.Add(text);

1 个答案:

答案 0 :(得分:0)

我只看了你发布的代码,我找到了解决方案:

替换它:

<DataTemplate>
    <StackPanel Orientation="Horizontal">
        <TextBlock Height="30" Text="" Margin="2,10" Name="textBlock1" DoubleTap="TextBlock_DoubleTap" Visibility="Visible"/>
    </StackPanel>
</DataTemplate>

用这个:

<DataTemplate>
    <TextBlock 
        Height="30" Text="{Binding}" Margin="2,10" 
        Name="textBlock1" DoubleTap="TextBlock_DoubleTap" 
        Visibility="Visible"/>
</DataTemplate>