wpf - No binding to IValueConverter DependencyProperty Occuring -


for wpf datagrid, i'm using ivalueconverter inherits dependencyobject, can add parameters. problem converter not being notified parameters have changed. when convert function runs, properties default values.

here's of code. note property names have been changed protect innocent.

xaml:

<usercontrol x:class="uselesstool"              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              xmlns:my="clr-namespace:lots.of.useless.stuff"              x:name="myself">   <grid x:name="layoutroot">     <grid.resources>       <my:invasiveweightconverter x:key="totalweightconverter"                                   department="{binding department, elementname=myself}" />     </grid.resources>     <datagrid x:name="buildinggrid"               itemssource="{binding buildingdata, elementname=myself}">       <datagrid.columns>         <datagridtextcolumn header="building"                             binding="{binding building}" />         <datagridtextcolumn header="room"                             binding="{binding room}" />         <datagridtextcolumn header="fire escapes"                             binding="{binding fireescapes}" />         <datagridtextcolumn header="total personnel weight"                             binding="{binding room, converter={staticresource totalweightconverter}, mode=twoway}" />       </datagrid.columns>     </datagrid>   </grid> </usercontrol> 

code behind (vb.net):

imports system.data imports system.componentmodel public class uselesstool   implements inotifypropertychanged    public sub new()     me.department = ""     me.buildingdata = new datatable   end sub    public sub importtables(buildingtable datatable, department string)      me.department = department      me.buildingdata = buildingtable.select("[department] = " & department).copytodatatable()   end sub    private _dept string   public property department() string           return _dept     end     set(value string)       _dept = value       raisepropertychanged("department")     end set   end property   .... end class  public class invasiveweightconverter   inherits dependencyobject   implements ivalueconverter    public shared readonly departmentproperty dependencyproperty = dependencyproperty.register("department", gettype(string), gettype(invasiveweightconverter), new propertymetadata(nothing, new propertychangedcallback(addressof dpchangehandler)))    public property department() string                 return directcast(getvalue(departmentproperty), string)       end       set(value string)           setvalue(departmentproperty, value)       end set   end property    private shared sub dpchangehandler(d dependencyobject, e dependencypropertychangedeventargs)     msgbox(e.newvalue.tostring)     ' part above not being fired   end sub    public function convert(value object, targettype system.type, parameter object, culture system.globalization.cultureinfo) object implements system.windows.data.ivalueconverter.convert     dim room string = ctype(value, string)      dim datatable datatable = personnel_table     dim clause string = string.format("[{0}] = '{1}' , [{2}] = '{3}'", datatable.departmentcolumn.tostring, department, datatable.roomcolumn.tostring, room)     ' notice department empty     dim rows() datarow = datatable.select(clause, "", dataviewrowstate.currentrows)      dim totalweight integer     dim weight integer     each row in rows         weight = cint(row.item("weight"))         totalweight += weight      next     return totalweight     end function    public function convertback(value object, targettype system.type, parameter object, culture system.globalization.cultureinfo) object implements system.windows.data.ivalueconverter.convertback     return nothing   end function  end class 

the easiest way pass more 1 parameter converter use multibinding

c#

public class totalweightconverter : imultivalueconverter {     public override object convert(object[] values, type targettype, object parameter, cultureinfo culture)     {         resulttype result;         var room =(roomtype)value[0];         var department = (departmenttype)value[1];          //         return result;     }      public override object[] convertback(object value, type[] targettypes, object parameter, cultureinfo culture)     {         // somethig         return new object[2];     } } 

xaml:

<datagridtextcolumn header="total personnel weight">     <datagridtextcolumn.binding>         <multibinding converter={staticresource totalweightconverter}>             <binding path="room" />             <binding path="department" mode="oneway"/>         </multibinding>     </datagridtextcolumn> </datagridtextcolumn> 

but best way descriped highcore


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -