好吧,我覺得這有點笨,但是,我有一個模板類MyClass或任何其他類型的列表視圖,每當我「myListView.Add(new MyClass())」winrt平臺添加一個新的UIElement並綁定適當現在,我希望能夠遍歷這些邏輯項目(myListView.Items或myListView.SelectedItems)並獲得它們相應的動畫UIElement,這可能嗎?如何在列表視圖中獲取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,它被用來表示這個邏輯數據類PhoneBookEntry在te模擬列表視圖。 此外,這種必然性伴隨着一個非常大的問題,我在哪裏,選定的項目在Windows Phone上沒有視覺上的差異-_-任何想法?
我已經用此解決方案進行了測試和研究,它直接回應了基本問題ty。 – Felype 2014-10-02 12:01:06