c# - Clone a WPF element with a Setter -
in wpf application, have tabcontrol tabitems :
<tabitem.header> <stackpanel orientation="horizontal"> <textblock name ="tabheader"/> <image margin="7,0,0,0"> <image.style> <style> <setter property="image.source" value="pictures/croixrouge.png"/> // no error without line </style> </image.style> </image> </stackpanel> </tabitem.header>
and clone tabitem add 1 in tabcontrol following function :
tabitem ti = (tabitem)_tabcontrollist.items.getitemat(_tabcontrollist.items.count - 1); tabitem ticloned= trycloneelement<tabitem>(ti); private static t trycloneelement<t>(t orig) { try { string s = system.windows.markup.xamlwriter.save(orig); // error : impossible serialize non-public type 'system.windows.media.imaging.bitmapframedecode' stringreader stringreader = new stringreader(s); xmlreader xmlreader = xmltextreader.create(stringreader, new xmlreadersettings()); xmlreadersettings sx = new xmlreadersettings(); object x = system.windows.markup.xamlreader.load(xmlreader); return (t)x; } catch { return (t)((object)null); } }
why error appear ? when place image :
<tabitem.header> <stackpanel orientation="horizontal"> <textblock name ="tabheader"/> <image margin="7,0,0,0" source="pictures/croixrouge.png"/> </stackpanel> </tabitem.header>
i have no problem. have use <setter...>
change image source on mouse hover.
Comments
Post a Comment