您的位置:首页 > 其它

WP7之LongListSelector控件

2012-07-12 15:57 183 查看
1.引用:

2.xaml:

FontFamily="{StaticResource PhoneFontFamilySemiBold}"

FontSize="48"

Margin="8,0,0,0"

Foreground="White"

VerticalAlignment="Bottom"/>

Padding="8,0,0,0" Width="62" Height="62"

HorizontalAlignment="Left">

Foreground="#FFFFFF"

FontSize="48"

FontFamily="{StaticResource PhoneFontFamilySemiLight}"

HorizontalAlignment="Left"

VerticalAlignment="Bottom"/>

3.后台cs代码

public partial class MainPage : PhoneApplicationPage

{

// Constructor

public MainPage()

{

InitializeComponent();

Loaded += new RoutedEventHandler(MainPage_Loaded);

LongList.SelectionChanged += new SelectionChangedEventHandler(LongList_SelectionChanged);

}

void LongList_SelectionChanged(object sender, SelectionChangedEventArgs e)

{

if (LongList.SelectedItem != null)

{

var d = LongList.SelectedItem as mydata;

if (d != null)

{

}

}

}

void MainPage_Loaded(object sender, RoutedEventArgs e)

{

List> dt = new List>();

for (int i = 0; i < 10; i++)

{

dt.Add(new Group(i.ToString(), getContent(i)));

}

LongList.ItemsSource = dt;

}

IEnumerable getContent(int k)

{

List dt = new List();

for (int i = 0; i < 10; i++)

{

dt.Add(new mydata() { Name = i.ToString() + "key", Content = i.ToString() + "val" });

}

return dt;

}

}

public class Group : IEnumerable

{

public Group(S groupItem, IEnumerable items)

{

this.GroupItem = groupItem;

this.Items = new List(items);

}

public override bool Equals(object obj)

{

Group other = obj as Group;

return (other != null) && (GroupItem.Equals(other.GroupItem));

}

public override int GetHashCode()

{

return GroupItem.GetHashCode();

}

public S GroupItem { get; set; }

public IList Items { get; set; }

public IEnumerator GetEnumerator()

{

return Items.GetEnumerator();

}

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()

{

return Items.GetEnumerator();

}

}

public class mydata

{

public string Name { get; set; }

public string Content { get; set; }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: