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>