将xaml添加到Listbox的顶部

时间:2014-05-06 23:59:20

标签: c# xaml windows-phone-8 listbox

我有一个列表框,里面装满了从数据合同中获取的项目。我想在列表框的顶部添加一些xaml,它从另一个数据协定中获取数据。我该怎么做呢?

<phone:PivotItem>
    <ScrollViewer>
        <StackPanel>
            <ListBox x:Name="StatusCommentsList"
                Background="Transparent"
                ItemsSource="{Binding StatusComments}"
                u:ScrollViewerMonitor.AtEndCommand="{Binding FetchMoreStatusCommentsDataCommand}" VerticalContentAlignment="Top">

                <!-- THIS DOESNT WORK-->          

                <ListBoxItem>
                    <Grid Height="auto">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="67" />
                            <ColumnDefinition Width="389"/>
                        </Grid.ColumnDefinitions>
                        <StackPanel Height="auto" Grid.Column="0" Background="Transparent">
                            <Border Background="Transparent" BorderThickness="0" Width="62" Height="62" HorizontalAlignment="Left" Margin="0,0,0,5">
                                <Image Source="{Binding Notification.context.data.created_by.image.thumbnail_link}" Width="62" Height="62"></Image>
                            </Border>
                        </StackPanel>
                        <StackPanel Height="auto" Grid.Column="1" Width="389" MaxWidth="389" Orientation="Vertical" >
                            <TextBlock TextWrapping="Wrap" Text="{Binding Notification.context.data.created_by.name}" HorizontalAlignment="Stretch" FontSize="30" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" Width="389" MaxWidth="389" />
                            <TextBlock TextWrapping="Wrap" Text="{Binding Notification.context.data.created_on}" HorizontalAlignment="Stretch" FontSize="30" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" Width="389" MaxWidth="389" />
                            <TextBlock TextWrapping="Wrap" Text="{Binding Notification.context.data.rich_value}" HorizontalAlignment="Stretch" FontSize="30" VerticalAlignment="Top" Margin="0,0,0,5" Foreground="White" Width="389" MaxWidth="389" />
                        </StackPanel>
                    </Grid>
                </ListBoxItem>

                <!-- /THIS DOESNT WORK -->

                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel VerticalAlignment="Top" Margin="5,0,0,0">
                            <Button Style="{StaticResource JamesTransparentButton}" Padding="-5,0,-5,-5" Margin="-7,-12,-7,-7" Height="auto" BorderThickness="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" UseLayoutRounding="True" FontSize="0.01">
                                <Grid Height="auto">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="67" />
                                        <ColumnDefinition Width="389"/>
                                    </Grid.ColumnDefinitions>
                                    <StackPanel Height="auto" Grid.Column="0" Background="Transparent">
                                        <Border Background="Transparent" BorderThickness="0" Width="62" Height="62" HorizontalAlignment="Left" Margin="0,0,0,5">
                                            <Image Source="{Binding created_by.image.thumbnail_link}" Width="62" Height="62"></Image>
                                        </Border>
                                    </StackPanel>
                                    <StackPanel Height="auto" Grid.Column="1" Width="389" MaxWidth="389" Orientation="Vertical" >
                                        <TextBlock Text="{Binding created_by.name}" FontSize="30" VerticalAlignment="Top" Margin="0,0,0,5" Foreground="White" />
                                        <TextBlock Text="{Binding created_on}" FontSize="30" VerticalAlignment="Top" Margin="0,0,0,5" Foreground="White" />
                                        <TextBlock TextWrapping="Wrap" Text="{Binding value}" HorizontalAlignment="Stretch" FontSize="30" VerticalAlignment="Top" Margin="0,0,0,5" Foreground="White" Width="389" MaxWidth="389" />
                                    </StackPanel>
                                </Grid>
                            </Button>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>
    </ScrollViewer>
</phone:PivotItem>

我尝试在列表框中添加一个新项目,但数据合同意味着我必须实例化对象的所有子级别,因为它们是不同的域,它会suckkk。

请记住,我希望整个屏幕以联合方式滚动...这样它看起来像一个很长的列表,无论第一个是默认值。

1 个答案:

答案 0 :(得分:0)

将第一个项目放在ListBox之外,并为ListBox禁用ScrollViewer,这样整个事物就会一起滚动。这是一个示例,其中项目是一个简单的TextBlock。您可以根据自己的要求进行更改。

<ScrollViewer>
       <StackPanel Orientation="Vertical">
                <TextBlock Text="Item 1"/>
                <ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding item}"/>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                 </ListBox>
        </StackPanel>
</ScrollViewer>