windows runtime - How do I do bindings in ItemContainerStyle in WinRT? -


i'm trying bind collection itemscontrol, canvas items panel, , each item's canvas.left , top bound properties on item objects. i'm trying re-create 2-d databinding described in this post on blog, time in winrt instead of wpf.

since itemscontrol wraps itemtemplate content in ui element (a contentpresenter, in case of winrt), , it's wrapper/container elements placed directly inside items panel, left , top have set on containers; can't set them in datatemplate. in wpf, it's easy enough bindings in itemcontainerstyle, e.g.:

<itemscontrol.itemcontainerstyle>     <style>         <setter property="canvas.left" value="{binding path=x}"/>         <setter property="canvas.top" value="{binding path=y}"/>     </style> </itemscontrol.itemcontainerstyle> 

but when try same thing in winrt/xaml project, nothing. not binding errors. if hard-code value, works; if use binding, property stays @ default value (zero), , no binding errors shown in output window.

<itemscontrol.itemcontainerstyle>     <style targettype="contentpresenter">         <!-- works, itemcontainerstyle work in winrt: -->         <setter property="canvas.left" value="200"/>         <!-- silently fails, leaves top 0, , not show              binding errors in debugger's output window: -->         <setter property="canvas.top" value="{binding y}"/>     </style> </itemscontrol.itemcontainerstyle> 

i've verified contentpresenters have correct datacontext (i.e. collection item, not collection or else funky), you'd think these bindings work fine. don't seem evaluated. if put bad binding anywhere else, , run debug build, see binding errors in debugger's output window; if reference nonsense property inside itemcontainerstyle, no binding errors shown.

here's more complete example, (as far know) should work fine in wpf, leaves @ origin in winrt:

<itemscontrol itemssource="{binding tiles}">     <itemscontrol.itemspanel>         <itemspaneltemplate>             <canvas/>         </itemspaneltemplate>     </itemscontrol.itemspanel>     <itemscontrol.itemcontainerstyle>         <style targettype="contentpresenter">             <setter property="canvas.left" value="{binding datacontext.left}"/>         </style>     </itemscontrol.itemcontainerstyle>     <itemscontrol.itemtemplate>         <datatemplate>             <rectangle width="80" height="80" fill="gray"/>         </datatemplate>     </itemscontrol.itemtemplate> </itemscontrol> 

i've tried few of more exotic options on binding -- relativesource. when used relativesource templatedparent, do-nothing behavior unchanged. however, when used relativesource self, did binding error, saying property didn't exist on type setter! it's taking self little literally, there.

i played around templatebinding, never grokked that's supposed used for, , got incomprehensible com errors (welcome winrt, huge technological step backward).

how can either (a) make bindings work correctly (are there other options on binding use coerce work properly?), or (b) otherwise allow items in itemscontainer positioned arbitrarily on canvas based on databindings properties on collection items?

bindings not supported on setters. think silverlight got them in version 5 if @ all. workarounds can @ older article here. define attached dependency property sets binding you.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -