这是我的Xaml.cs中的一个方法:
void itemListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.UsingLogicalPageNavigation())
{
this.navigationHelper.GoBackCommand.RaiseCanExecuteChanged();
}
// Here is the object which properties i am trying to get:
var mySelectedItem = e.AddedItems[0];
//Here I would like to acess the properties
}
我试图用反射从mySelected Item中获取属性。 一直在尝试:
PropertyInfo property = GetType().GetProperty(propertyName) <--Cant resolve GetProperty()
和
object value = propertyInfo.GetValue(mySelectedItem);<--Cant resolve PropertyInfo
在这种情况下,是否不可能使用refelction?
答案 0 :(得分:1)
你不需要反思你想要的东西。
将对象投射到正确的对象时,可以访问对象的属性。
void itemListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (this.UsingLogicalPageNavigation())
{
this.navigationHelper.GoBackCommand.RaiseCanExecuteChanged();
}
var mySelectedItem = e.AddedItems[0];
MyObject myObject = (MyObject)mySelectedItem;
// Now you can access your property as follows: myObject.MyProperty;
}