a reoccurring issue have needing create enhanced text columns datagrids. mean columns act normal text columns, additional graphic or feature, image displayed next text. i'm using template columns, apparently means having "start scratch" in generating lot of features expected of normal text column, such textbox editing template:
<datagridtemplatecolumn.celleditingtemplate> <datatemplate> <textbox focusmanager.focusedelement="{binding relativesource={relativesource self}}" text="{binding path=[binded text], mode=twoway, updatesourcetrigger=lostfocus}"/>
i want define column that's inherited datagridtemplatecolumn, dump code it, can reuse these columns datagrid wish. shown above, can't declare binding in class definition because depends upon usage.
how can define inherited datagrid column makes use of child controls (specifically cell editing textbox in case), still allows binding set these controls when column has been declared xaml inside actual datagrid?
so far i've tried expose method this, it's not working:
public class mytextcolumn inherits datagridtemplatecolumn .... public property editorbinding string get.... set(value string) dim b new binding(value) b.mode = bindingmode.twoway b.updatesourcetrigger = updatesourcetrigger.lostfocus dim tb = directcast(me.celleditingtemplate.loadcontent, textbox) tb.setbinding(textbox.textproperty, b) end set end property
not working, best guess i'm not setting binding.source
, have no idea should setting to. it's getting pretty frustrating.
so if understand correctly, want able bind text property of textbox on parent control hold child control of yours. can't using normal property (i'm guessing got "can't bind because it's not dependency property" exception or similar).
this how without problems. first need define dependency property in code behind. this should show how in vb.net (i really suck @ vb.net won't pretend give advice on that). check first example in vb.net. need change first boolean string, want change property name. careful leave "property" part of name stands in example. gettype(mycode)
should changed name of class implementing dependency property (the name of mytextcolumn
class)
in mytextcolumn xaml, should this:
<datagridtemplatecolumn.celleditingtemplate> <datatemplate> <textbox focusmanager.focusedelement="{binding relativesource={relativesource self}}" text="{binding path=isspinning, relativesource={relativesource ancestortype=datagridtemplatecolumn}, mode=twoway, updatesourcetrigger=lostfocus}"/>
i've put original property name isspinning, should put there chosen name. also, might have fix relative source if base class not datagridtemplatecolumn. should pick comming custom control.
the final step use control:
<controls:mytextcolumn isspinning="{binding propname}"/>
you bind whatever string want. feel free write problems might have explanation or code , i'll fix answer accordingly.
Comments
Post a Comment