You need to cast btn.DataContext
to LVData
:
var lvData = (LVData)btn.DataContext;
// now you can access lvData.Name, ...
You receive a compile error because btn.DataContext
is of type object and doesn't know anything about LVData
members. At runtime, it can point to any class instance (because all classes inherit from object
). You tell the compiler that btn.DataContext
points to a LVData
instance by casting it.
(More explanations here: polymorphism, casting. You will need this all the time.)