Modify text in column cells and make it hyperlink, listView WPF C# -
for displaying in 1 of columns in listview, gridview 1 of property of class. looks more or less:
<listview x:name="offers_listview" margin="38,185,35,81" > <listview.view> <gridview> <gridviewcolumn width="100" header="itemid" displaymemberbinding="{binding path=itemid}" />
itemid number.
what make hyperlink based on number. example itemid equals 1234 make clickable link address www.website.com/showitem.php?itemid=1234. best solution if column still display 1234 clickable link address mentioned. of course whole list, each item have different itemid property.
may give me hint how or sample of code can based ?
edit:
solution gave below have been adapted me.
however on logic side navigateuri have been null, link opened in browser have been not correct. have adapt idea directly textblock paste code below:
<gridviewcolumn width="100" header="itemlink"> <gridviewcolumn.celltemplate> <datatemplate> <textblock text="{binding path=itemid}" mousedown="textblock_mousedown"/> </datatemplate> </gridviewcolumn.celltemplate> </gridviewcolumn> private void textblock_mousedown(object sender, mousebuttoneventargs e) { var urlpart2 = ((textblock)sender).text; //var urlpart = ((hyperlink)sender).navigateuri; var fullurl = string.format("http://allegro.pl/show_item.php?item={0}", urlpart2); process.start(new processstartinfo(fullurl)); e.handled = true; }
you need change cell template gridviewcolumn in order have column contain hyperlinks.
for example, following:
<gridviewcolumn.celltemplate> <datatemplate> <textblock> <hyperlink navigateuri="{binding path=itemid}" requestnavigate="hyperlink_onrequestnavigate"> <textblock text="{binding path=itemid}"/> </hyperlink> </textblock> </datatemplate> </gridviewcolumn.celltemplate>
will have given column filled hyperlinks. wpf doesn't hyperlinks default, have add handler opens link:
private void hyperlink_onrequestnavigate(object sender, requestnavigateeventargs e) { var urlpart = ((hyperlink)sender).navigateuri; var fullurl = string.format("http://www.website.com/showitem.php?itemid={0}", urlpart); process.start(new processstartinfo(fullurl)); e.handled = true; }
of course, change url whatever want do.
Comments
Post a Comment