如何在WP8中自定义LongListSelector或ListBox设计

时间:2013-11-13 10:01:58

标签: c# .net windows-phone-8 listbox windows-phone

我想以自己的方式自定义我的LongListSelector或ListBox,所以任何人都可以帮我设计它..
我的代码..

<StackPanel HorizontalAlignment="Left" Height="345" Margin="10,234,0,0" VerticalAlignment="Top" Width="413">
                <phone:LongListSelector x:Name="list_organization" Height="340" Margin="10,0"/>

</StackPanel>

这是我绑定长列表的代码..

org = await client.searchOrganization(txtQuery.Text);
            if (org != null)
            {
                var query = from c in org
                            select new { c.name,c.id,c.time,.. };
                list_organization.ItemsSource = query.ToList();//bind the query to longlist
            }

我想要这个设计页面..

enter image description here

怎么做......?

1 个答案:

答案 0 :(得分:1)

首先,删除显式宽度和高度。如果您在LongListSelector中只有一个StackPanel,则可以删除StackPanel

类似列表框的容器的各个项目是使用DataTemplate替换ItemTemplate完成的。有关详细信息,请查看以下MSDN链接:ListBox Styles and Templates

基本上,这是你如何做到的:

<phone:LongListSelector x:Name="list_organization" Height="340" Margin="10,0"
                        ItemsSource="{Binding People}">
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            <!-- your XAML for individual item goes here -->
            <TextBlock Text="{Binding FirstName}" />
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>