c# - Windows 8.1 Handle potentially different data types -
i have gridview can fire holding event on item. items consist of stackpanel
, textblock
, image
handling below code
private async void gvjobs_holding(object sender, windows.ui.xaml.input.holdingroutedeventargs e) { joblocal job = null; if(e.originalsource textblock) { job = (joblocal)((textblock)e.originalsource).datacontext; } else if (e.originalsource image) { job = (joblocal)((image)e.originalsource).datacontext; } else if (e.originalsource stackpanel) { job = (joblocal)((stackpanel)e.originalsource).datacontext; } ....code based on above result }
but feel there better way using multiple if statements. tried using var
cannot access datacontext
please advise on better way achieve objective
your ui elements derived frameworkelement
can cast this.
if (e.originalsource frameworkelement) { job = (joblocal)((frameworkelement) e.originalsource).datacontext; }
Comments
Post a Comment