c# - How Do I Set Z-Index in an ItemsControl with a Data Binding? -
there several answers none of them work uwp, wpf. have custom itemscontrol dynamically places children in unusual pattern based on properties within child's respective view model. items partially overlap , need ensure selected item not hidden beneath other items. cannot figure out how bind value grid's z-index.
<itemscontrol name="myitemscontrol" itemssource="{x:bind pageviewmodel.mycollectionofmyviewmodel}" rendertransformorigin="0.5,0.5" > <itemscontrol.rendertransform> <compositetransform x:name="mytransform" /> </itemscontrol.rendertransform> <itemscontrol.itemspanel> <itemspaneltemplate> <grid /> </itemspaneltemplate> </itemscontrol.itemspanel> <itemscontrol.itemtemplate> <datatemplate x:datatype="viewmodel:myviewmodel"> <grid name="itemgrid" canvas.zindex="{x:bind selecteditem, mode=oneway, converter={staticresource selecteditemtozindexconverter}}" rendertransformorigin="0.5,0.5" > <grid.rendertransform> <compositetransform rotation="{binding itemidxnum, mode=oneway, converter={staticresource itemidxtorotationangleconverter}}" translatex="{binding itemidxnum, mode=oneway, converter={staticresource itemidxtoxposconverter}}" translatey="{binding itemidxnum, mode=oneway, converter={staticresource itemidxtoyposconverter}}" scalex="{x:bind selecteditem, mode=oneway, converter={staticresource selecteditembooltoscaleconverter}}" scaley="{x:bind selecteditem, mode=oneway, converter={staticresource selecteditembooltoscaleconverter}}" /> </grid.rendertransform> <stackpanel orientation="horizontal"> <textblock text="{x:bind itemname, mode=oneway}"/> </stackpanel> </grid> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol>
the canvas.zindex in there not throw build error doesn't work. searching here , elsewhere seems need target itemscontrol's contentpresenter instead of child elements. don't know how go this. examples wpf , use style triggers target type aren't available in uwp.
looks typo. it's capital i
in zindex
.
canvas.zindex="..." <!-- right --> canvas.zindex="..." <!-- wrong -->
update
itemscontrol
wrap items contentpresenter
, can override functionality creating own version. use instead of itemscontrol
:
public class myitemscontrol : itemscontrol { protected override dependencyobject getcontainerforitemoverride() { return itemtemplate?.loadcontent() ?? base.getcontainerforitemoverride(); } protected override void preparecontainerforitemoverride(dependencyobject element, object item) { ((frameworkelement) element).datacontext = item; } }
and xaml can use switching out root level tag myitemscontrol
<local:myitemscontrol name="myitemscontrol" itemssource="{x:bind pageviewmodel.mycollectionofmyviewmodel}" rendertransformorigin="0.5,0.5"> <itemscontrol.rendertransform> <compositetransform x:name="mytransform" /> </itemscontrol.rendertransform> <itemscontrol.itemspanel> <itemspaneltemplate> <grid /> </itemspaneltemplate> </itemscontrol.itemspanel> <itemscontrol.itemtemplate> <datatemplate x:datatype="viewmodel:myviewmodel"> <grid name="itemgrid" canvas.zindex="{x:bind selecteditem, mode=oneway, converter={staticresource selecteditemtozindexconverter}}" rendertransformorigin="0.5,0.5"> <grid.rendertransform> <compositetransform rotation="{binding itemidxnum, mode=oneway, converter={staticresource itemidxtorotationangleconverter}}" translatex="{binding itemidxnum, mode=oneway, converter={staticresource itemidxtoxposconverter}}" translatey="{binding itemidxnum, mode=oneway, converter={staticresource itemidxtoyposconverter}}" scalex="{x:bind selecteditem, mode=oneway, converter={staticresource selecteditembooltoscaleconverter}}" scaley="{x:bind selecteditem, mode=oneway, converter={staticresource selecteditembooltoscaleconverter}}" /> </grid.rendertransform> <stackpanel orientation="horizontal"> <textblock text="{x:bind itemname, mode=oneway}" /> </stackpanel> </grid> </datatemplate> </itemscontrol.itemtemplate> </local:myitemscontrol>
Comments
Post a Comment