本文介绍了如何以编程方式创建 LongListSelector 控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是另一个 LongListSelector 问题..

This is yet another LongListSelector question..

我需要一些具有这种风格的选择器并为它们添加不同的绑定:

I need to have some selectors with this style and add different bindings to them:

<phone:LongListSelector x:Name="ListSelector">
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            <StackPanel Name="containerStack" Margin="0,0,0,0" Orientation="Horizontal">
                <StackPanel HorizontalAlignment="Left" Height="Auto" VerticalAlignment="Top" Width="60" Margin="3,20,2,20">
                    <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" FontSize="{StaticResource PhoneFontSizeMedium}" Foreground="White"/>
                </StackPanel>
                <StackPanel Height="Auto" VerticalAlignment="Top" Width="350" Margin="2,20,3,20">
                    <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" FontSize="{StaticResource PhoneFontSizeMedium}" Foreground="White" Margin="0"/>
                    <TextBlock TextWrapping="Wrap" Style="{StaticResource PhoneTextLargeStyle}" FontSize="{StaticResource PhoneFontSizeMedium}" Foreground="DarkBlue" Margin="0"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>

我想以编程方式实现.我看到了这个答案,但这在 Windows Phone 8 中对我不起作用.

I want to make it programmatically. I saw this answer, but that didn't work for me in windows phone 8.

如何通过代码或样式重现它?谢谢

How can I reproduce it by code or as a style? thanks

推荐答案

希望你知道如何在 longlistSelector 中绑定数据.假设下面是代码.尝试自己绑定它.

I hope you know how to bind data in longlistSelector. Assuming that below is the code. Try to Bind it on your own.

    LongListSelector listSelector;

    private void CreateLongListSelector()
    {
        listSelector = new LongListSelector()
        {
            HideEmptyGroups=false,
            IsGroupingEnabled=false,
        };
        ContentPanel.Children.Add(listSelector);
        listSelector.ItemTemplate = GetDataTemplate();

    }

    public DataTemplate GetDataTemplate()
    {
        string xaml = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
                        <StackPanel Name=""containerStack"" Margin=""0,0,0,0"" Orientation=""Horizontal"">
                        <StackPanel HorizontalAlignment=""Left"" Height=""Auto"" VerticalAlignment=""Top"" Width=""60"" Margin=""3,20,2,20"">
                        <TextBlock Text=""{Binding text}"" TextWrapping=""Wrap"" Style=""{StaticResource PhoneTextLargeStyle}"" FontSize=""{StaticResource PhoneFontSizeMedium}"" Foreground=""White""/>
                        </StackPanel><StackPanel Height=""Auto"" VerticalAlignment=""Top"" Width=""350"" Margin=""2,20,3,20"">
                        <TextBlock Text=""{Binding text}"" TextWrapping=""Wrap"" Style=""{StaticResource PhoneTextLargeStyle}"" FontSize=""{StaticResource PhoneFontSizeMedium}"" Foreground=""White"" Margin=""0""/>
                        <TextBlock Text=""{Binding text}"" TextWrapping=""Wrap"" Style=""{StaticResource PhoneTextLargeStyle}"" FontSize=""{StaticResource PhoneFontSizeMedium}"" Foreground=""DarkBlue"" Margin=""0""/>
                        </StackPanel>
                        </StackPanel>
                        </DataTemplate>";
        DataTemplate res=null;
        try
        {
            res = (DataTemplate)XamlReader.Load(xaml);
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }
        return res;
    }

这篇关于如何以编程方式创建 LongListSelector 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 06:20