c# - Binding error on XmlDataProvider (cannot bind to non-XML object) -


i have problem on binding controls xml.
application populates tabcontrol @ runtime, loading xaml tab datatemplateselector:

class templateselector : datatemplateselector {   public override datatemplate selecttemplate(object item, dependencyobject container)   {     if (item != null)     {       string templatefile = string.format("templates/{0}",                                            properties.settings.default.appid + ".tmpl");       if (file.exists(templatefile))       {         filestream fs = new filestream(templatefile, filemode.open);         datatemplate template = xamlreader.load(fs) datatemplate;          tab tab = item tab;         xmldataprovider xmldataprovider = template.resources["dataprovider"] xmldataprovider;         xmldataprovider.xpath = tab.bridgeobj.xmlfilepath;          return template;       }     }     return null;   } } 

the xaml:

<datatemplate     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:local="clr-namespace:eurocomcps;assembly=eurocomcps">    <datatemplate.resources>     <local:stringtoboolconverter x:key="strtoboolconverter" />     <local:stringtointconverter  x:key="strtointconverter" />     <xmldataprovider x:key="dataprovider" xpath="func/parametri/param/blocks"/>   </datatemplate.resources>    <grid>     <grid.rowdefinitions>         <rowdefinition height="auto" />         <rowdefinition height="auto" />         <rowdefinition height="auto" />         <rowdefinition height="auto" />     </grid.rowdefinitions>     <grid.columndefinitions>         <columndefinition width="100" />         <columndefinition width="auto" />     </grid.columndefinitions>      <label grid.row="0" grid.column="0" content="item 1:"/>     <label grid.row="1" grid.column="0" content="item 2:"/>     <label grid.row="2" grid.column="0" content="item 3:"/>      <textbox  name="textbox1"               grid.row="0"                grid.column="1"                text="{binding xpath='//block[@id=1]/items/item[@id=1]/@value'}" />     <checkbox grid.row="1"                grid.column="1"               ischecked="{binding xpath='//block[@id=1]/items/item[@id=2]/@value',                             converter={staticresource strtoboolconverter}}"/>      <checkbox grid.row="2"                grid.column="1"               ischecked="{binding xpath='//block[@id=1]/items/item[@id=3]/@value',                             converter={staticresource strtoboolconverter}}"/>    </grid> </datatemplate> 

every page hold xmldataprovider load following xml file:

<func id="a29086">   <parametri>     <param>       <blocks max_count="2" write_id="49" read_req_id="47" read_rep_id="48" session_id="7">         <block id="1" frame="1" framelen="61">           <items max_count="14">             <item id="1" type="char" size="1" value="0" />             <item id="2" type="char" size="1" value="1" />             <item id="3" type="char" size="1" value="0" />             ...           </items>         </block>         <block id="2" frame="1" framelen="61">           <items max_count="14">             <item id="1" type="char" size="1" value="0" />             <item id="2" type="char" size="1" value="1" />             ...           </items>         </block>       </blocks>     </param>   </parametri> </func> 

when running error:

system.windows.data error: 44 : bindingexpression xpath cannot bind non-xml object.; xpath='//block[@id=1]/items/item[@id=1]/@value' bindingexpression:path=/innertext; dataitem='tab' (hashcode=57706919); target element 'textbox' (name=''); target property 'text' (type 'string') tab:'eurocomcps.tab' system.windows.data error: 44 : bindingexpression xpath cannot bind non-xml object.; xpath='//block[@id=1]/items/item[@id=2]/@value' bindingexpression:path=/innertext; dataitem='tab' (hashcode=57706919); target element 'checkbox' (name=''); target property 'ischecked' (type 'nullable`1') tab:'eurocomcps.tab' system.windows.data error: 44 : bindingexpression xpath cannot bind non-xml object.; xpath='//block[@id=1]/items/item[@id=3]/@value' bindingexpression:path=/innertext; dataitem='tab' (hashcode=57706919); target element 'checkbox' (name=''); target property 'ischecked' (type 'nullable`1') tab:'eurocomcps.tab' 

--- edit ---

i add datacontext controls still have problems.
the first following:

system.windows.data error: 44 : bindingexpression xpath cannot bind non-xml object.; xpath='//block[@id=1]/items/item[@id=1]/@value' bindingexpression:path=/innertext; dataitem='tab' (hashcode=46144604); target element 'textbox' (name=''); target property 'text' (type 'string') tab:'eurocomcps.tab' system.windows.data error: 44 : bindingexpression xpath cannot bind non-xml object.; xpath='//block[@id=1]/items/item[@id=1]/@value' bindingexpression:path=/innertext; dataitem='tab' (hashcode=46144604); target element 'textbox' (name='textbox1'); target property 'text' (type 'string') tab:'eurocomcps.tab' 

and don't understand first 'unnamed' textbox not defined anywhere.

second that, if put converter textbox binding (eg, 1 use checkboxes) don't error.

third converter functions not called.

assuming somehow load xml xmldataprovider, don't see source defined anywhere, xpath fine don't provide source binding. should work if change this:

<textblock text="{binding source={staticresource dataprovider}, xpath='//block[@id=1]/items/item[@id=2]/@value'}"/> 

if won't specify source default in datacontext.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -