wpf - Accessing ListBox DisplayMemberPath data value in SelectedItem template -


i attempting create generic listbox control customize edit in place other features.

in example below, want bind "text" property of listbox "selected item" data value of displaymemberpath in viewed structure. such xaml binding expression replace question marks in code (text="{binding ????????????????").

using contentpresenter instead of binding text works display purposes, have not been able bind text component used on presenter. alternative finding binding expression able text content contentpresenter.

i can think of number of ways accomplish through code behind, looking xaml solution if such thing exists.

i appreciate ideas. sure there trivial answer this, after spending couple days on it, admit nudge in right direction me.

<window x:class="wpfapplication1.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="mainwindow" height="350" width="525"> <window.resources>     <xmldataprovider x:key="nobellaureatesinphysics"                      xpath="/nobellaureatesinphysics">         <x:xdata>             <nobellaureatesinphysics xmlns="">                 <nobellaureate>                     <id>1</id>                     <name>wilhelm röntgen</name>                     <awarddate>12/10/1901</awarddate>                 </nobellaureate>                 <nobellaureate>                     <id>2</id>                     <name>hendrik lorentz</name>                     <awarddate>12/10/1902</awarddate>                 </nobellaureate>                 <nobellaureate>                     <id>3</id>                     <name>pieter zeeman</name>                     <awarddate>12/10/1902</awarddate>                 </nobellaureate>             </nobellaureatesinphysics>         </x:xdata>     </xmldataprovider>      <controltemplate x:key="itemtemplate"                      targettype="listboxitem">         <textblock foreground="black">              <contentpresenter />         </textblock>     </controltemplate>      <controltemplate x:key="selecteditemtemplate"                      targettype="listboxitem">         <textbox background="black"                  foreground="white"                  text="{binding ????????????????"/>     </controltemplate>      <style targettype="{x:type listboxitem}"            x:key="containerstyle">         <setter property="template"                 value="{staticresource itemtemplate}" />         <style.triggers>             <trigger property="isselected"                      value="true">                 <setter property="template"                         value="{staticresource selecteditemtemplate}" />             </trigger>         </style.triggers>     </style>      <style x:key="testlistboxstyle"            targettype="{x:type listbox}">         <setter property="itemcontainerstyle"                 value="{dynamicresource containerstyle}" />     </style> </window.resources>  <grid>     <listbox style="{dynamicresource testlistboxstyle}"              itemssource="{binding source={staticresource nobellaureatesinphysics}, xpath=nobellaureate}"              displaymemberpath="name"/> </grid> 

share|improve question
{binding path=displaymemberpath, relativesource={relativesource mode=findancestor, type={x:type listbox}} 

that should work

share|improve answer
1  
this listbox.displaymemberpath property, e.g. "name". believe poster wants value of property on item @ hand, e.g. "hendrik lorentz". – itowlson feb 9 '11 @ 22:43
    
oh silly me oo sorry. way go doing memberpathconverter. multivalueconverter takes listboxitem's value , binding listed above. reflection in converter find required property. – lugoues feb 9 '11 @ 22:55
    
as noted, intention value pointed displaymemberpath. e.g. if "nested" binding allowed, like: binding path={binding path=displaymemberpath, relativesource={relativesource mode=findancestor, type={x:type listbox}}}. also, converter or other code behind solutions available, wondering if either binding or property syntax offer more elegant/maintenable declarative solution. – juan m. medina feb 10 '11 @ 15:02


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -