wpf referencing value converter from within nested datatemplate (causing null reference exception) -


i experiencing troubles ivalueconverters called nested datatemplate (listviewitems).

i have complex (list of) objects containing other objects , lists of lists of objects (too source code put here)...

everything works fine except ivalueconverter implementation on deeper nesting levels...

simplifyed , shortened xaml:

    <window x:class="xxxx.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:converter="clr-namespace:xxxx.converter"     width="800"     height="600"     icon="/images/icons/calendar.ico"     loaded="window_loaded"     style="{staticresource windowdefaultstyle}"     windowstate="maximized"> <window.resources>     <!--  <converter:valuetovisibilityconverter x:key="valuetovisibility" />  -->     <converter:percentageconverter x:key="percentfromvalue" />     <converter:subtractionconverter x:key="substractfromvalue" />     <converter:singletextlineconverter x:key="insingleline" />     <converter:b2vconverter x:key="b2v" /> </window.resources>      <grid name="grid_supplier">         <listview name="listview_product"             grid.row="1"             height="{binding elementname=grid_supplier,             path=actualheight,             converter={staticresource substractfromvalue},             converterparameter=60}"             itemssource="{binding relativesource={relativesource mode=findancestor,             ancestortype=window},path=suppliersproducts}">                 <listview.itemtemplate>                     <datatemplate>                         <listview name="listview_cm"                                 width="{binding elementname=grid_supplierproduct,                                 path=actualwidth,                                 converter={staticresource percentfromvalue},                                 converterparameter=80}"                                 itemssource="{binding cm}">                                 <listview.itemtemplate>                                     <datatemplate>                                         <listview name="listview_comments"                                             itemssource="{binding comments}">                                             <listview.itemtemplate>                                                 <datatemplate>                                                     <textblock                                                             text="{binding comment.duedate, stringformat='dd.mm.yyyy'}"                                                             background="{binding status 

, converter={staticresource b2v}

}"/>                                                 </datatemplate>                                             </listview.itemtemplate>                                         </listview>                                     </datatemplate>                                 </listview.itemtemplate>                         </listview>                     </datatemplate>                 </listview.itemtemplate>         </listview>     </grid> </window> 

as can see there 3 nested listviews, converter (percentfromvalue) in "first" level working without problems - binding , parameter...

my problem @ next nesting "levels" converter part (staticresource b2v) of binding present, null reference exception risen @ runtime (no further explanations or nested exception infos available... - converter gone there no problem... ok no exception, no background - has expected... )

i have tried create "listview resource" part, there null reference exception risen (i assume "converter:" part of path can not found in case.

since using backgroundworker (information shown on gui collected more 9 related tables), there no possibility pass brush gui (inherits dispatcher , causes "dependencysource must created in same thread dependencyproperty" error).

now preparing in background , adding background-brush in same thread workaround, ugly...

it better use converter, how reference within nested datatemplate?

thank in advance help!

i have solved myself moving datatemplates in window.resources , making them refererence each other, creating "flat" structure not directly nested anymore...

<window x:class="xxxx.mainwindow"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:converter="clr-namespace:xxxx.converter"    width="800"    height="600"    icon="/images/icons/calendar.ico"    loaded="window_loaded"    style="{staticresource windowdefaultstyle}"    windowstate="maximized"> <window.resources>    <converter:percentageconverter x:key="percentfromvalue" />    <converter:subtractionconverter x:key="substractfromvalue" />    <converter:singletextlineconverter x:key="insingleline" />    <converter:b2vconverter x:key="b2v" />     <datatemplate x:key="commenttemplate"> <textblock text="{binding comment.duedate, stringformat='dd.mm.yyyy'}" background="{binding status, converter={staticresource b2v}}"    </datatemplate>     <datatemplate x:key="commentstemplate"> <listview name="listview_comments"           itemssource="{binding comments}"             itemtemplate={staticresource commenttemplate} />    </datatemplate>      <datatemplate x:key="cmtemplate">         <listview name="listview_cm"         width="{binding elementname=grid_supplierproduct,         path=actualwidth,         converter={staticresource percentfromvalue},         converterparameter=80}"         itemssource="{binding cm}"         itemtemplate={staticresource commentstemplate} />    </datatemplate>  </window.resources>  <grid name="grid_supplier">     <listview name="listview_product"         grid.row="1"         height="{binding elementname=grid_supplier,         path=actualheight, converter={staticresource substractfromvalue},         converterparameter=60}"         itemssource="{binding relativesource={relativesource mode=findancestor,         ancestortype=window},path=suppliersproducts}"         itemtemplate={staticresource cmtemplate}/> </grid> 

take care innermost template defined first , on. otherwise templates not found.

due structuring of file have "flat" on 1 level , converters found , referenced.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -