【发布时间】:2014-09-28 18:05:17
【问题描述】:
好的,我觉得这个问题有点愚蠢,但是,我有一个带有模板类 MyClass 或其他内容的列表视图,每当我“myListView.Add(new MyClass())”时,winrt 平台都会在那里添加一个新的 UIElement 并绑定正确的属性到正确的uielements中,现在,我希望能够遍历这些逻辑项(myListView.Items或myListView.SelectedItems)并获取它们对应的UIElement进行动画,这可能吗?
例如
class PhoneBookEntry {
public String Name { get;set }
public String Phone { get;set }
public PhoneBookEntry(String name, String phone) {
Name = name; Phone = phone;
}
};
myListView.Add(new PhoneBookEntry("Schwarzeneger", "123412341234");
myListView.Add(new PhoneBookEntry("Stallone", "432143214321");
myListView.Add(new PhoneBookEntry("Statham", "567856785678");
myListView.Add(new PhoneBookEntry("Norris", "666666666666");
在 XAML 中(只是一个例子,我可以解释我的意思)
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Phone}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
所以,我的观点和目标是
foreach(PhoneBookEntry pbe in myListView.Items) // or SelectedItems
{
UIElement el; // How can I get the UIElement associated to this PhoneBookEntry pbe?
if(el.Projection == null)
el.Projection = new PlaneProjection;
PlaneProjection pp = el.Projection as PlaneProjection;
// Animation code goes here.
if(myListView.SelectedItems.Contains(pbe)
//something for selected
else
//something for not selected
}
我只需要一种方法来获取一个 UIElement,该 UIElement 用于在模板化列表视图中表示这个逻辑数据类 PhoneBookEntry。 此外,这种必要性伴随着我遇到的一个非常大的问题,在 Windows Phone 上,所选项目在视觉上没有差异 -_- 有什么想法吗?
【问题讨论】:
标签: c# xaml windows-runtime windows-phone-8.1