I set list in one method:
private void SetList()
SomeList.ItemsSource = ( from someTable in data.SomeTable
Priority = someTable.Priority,
In other method I want retrieve Id of selected item. How can I do it? I have found interesting solution in blog of Tomas Petricek.
private Int32 GetID()
Object selectedItem = DefectList.SelectedItem;
if( null != selectedItem )
var item = Utility.Cast( selectedItem, new
Id = 0,
Name = String.Empty,
Priority = String.Empty,
Int32 id = item.Id;
public static T Cast
( object obj, T type )
PS: As for me the best way is:
- implement class with three like property.
- create collection with items of this class.
- set in ItemsSource new created collection.
- now we can easy case Object to this class.