无法在列表框中看到UI元素

时间:2014-05-08 05:36:57

标签: xaml layout windows-phone-8 windows-phone listbox-control

我有一个包含ListBox的页面。谁的项目不可见。但是我的ListBox可见,我通过更改其背景颜色来检查它。这是我的ListBox: -

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ListBox Name="friend_list"  Margin="0,10,0,0">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <Grid Width="{Binding ElementName=friend_list,Path=ActualWidth}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <StackPanel Grid.Column="1"  HorizontalAlignment="Left" Margin="0,30,80,10">
                                    <TextBlock  TextWrapping="Wrap" Text="Diana Jayson" Name="username" FontWeight="Bold" FontSize="40" Margin="12,0,0,0" Foreground="#FF4D6082" Width="250" />
                                    <TextBlock Text="Diana Jayson" Name="location" FontSize="40" Margin="20,0,0,0" Foreground="#FF4D6082"/>
                                    <TextBlock Text="Diana Jayson" Name="sate" FontSize="40" Margin="20,0,0,0" Foreground="#FF4D6082"/>
                                </StackPanel>

                                <Image  Grid.Column="0" Source="Assets\profile-placeholder.gif" Width="160" Height="160" Stretch="Fill" HorizontalAlignment="Left" Margin="10,0,0,0">
                                    <Image.Clip>
                                        <EllipseGeometry  Center="80,80" RadiusX="80" RadiusY="80" />
                                    </Image.Clip>
                                </Image>
                            </Grid>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

1 个答案:

答案 0 :(得分:1)

您必须将元素列表绑定到列表框才能显示其成员..

像这样....

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ListBox Name="friend_list"  ItemSource="{Binding yourlistname}" Margin="0,10,0,0">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <Grid Width="{Binding ElementName=friend_list,Path=ActualWidth}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <StackPanel Grid.Column="1"  HorizontalAlignment="Left" Margin="0,30,80,10">
                                    <TextBlock  TextWrapping="Wrap" Text="Diana Jayson" Name="username" FontWeight="Bold" FontSize="40" Margin="12,0,0,0" Foreground="#FF4D6082" Width="250" />
                                    <TextBlock Text="Diana Jayson" Name="location" FontSize="40" Margin="20,0,0,0" Foreground="#FF4D6082"/>
                                    <TextBlock Text="Diana Jayson" Name="sate" FontSize="40" Margin="20,0,0,0" Foreground="#FF4D6082"/>
                                </StackPanel>

                                <Image  Grid.Column="0" Source="Assets\profile-placeholder.gif" Width="160" Height="160" Stretch="Fill" HorizontalAlignment="Left" Margin="10,0,0,0">
                                    <Image.Clip>
                                        <EllipseGeometry  Center="80,80" RadiusX="80" RadiusY="80" />
                                    </Image.Clip>
                                </Image>
                            </Grid>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

在模板中,您可以直接将ui与列表对象中的属性绑定..

我希望这可能会有所帮助......