c# - Passing DataContext in Telerik RadGridView -
i use c# .net 4.5 , wpf radcontrols telerik.
on mainwindow
have radtabcontrol
, in code behind bind mainviewmodel
this:
this.datacontext = new mainviewmodel();
the itemsource
of radtabcontrol
bound in xaml:
<telerik:radtabcontrol ... itemssourc={binding tabs} .. />
i use contentselector
load different contents tabs. these contents usercontrols
. on 1 usercontrol
use radgridview
it's own itemssource
bind in code behind:
testgridview.itemssource = tasks.gettasks();
the radgridview columns
bound it's own style:
<telerik:radgridview.columns> <telerik:gridviewdatacolumn datamemberbinding="{binding id}" width="*" cellstyle="{staticresource cellstyle}" /> </telerik:radgridview.columns> <style x:key="cellstyle" targettype="{x:type telerik:gridviewcell}"> <setter property="borderthickness" value="0" /> <setter property="borderbrush" value="{x:null}" /> <setter property="template"> <setter.value> <controltemplate> <border borderbrush="#f2f2f2" borderthickness="0,0,0,2" padding="0,5,0,5"> <stackpanel orientation="horizontal"> <stackpanel orientation="vertical" margin="10,0,0,0" verticalalignment="top"> <textblock text="{binding titel}" /> <stackpanel orientation="horizontal"> <textblock text="{binding start}" foreground="#9fa2ae"/> <textblock text=" xxx - xxx " /> <textblock text="{binding startzeit}" foreground="#9fa2ae" /> <telerik:radbutton height="30" content="right button" command="{binding addtabcommand}" commandparameter="tab9999"/> </stackpanel> </stackpanel> </stackpanel> </border> </controltemplate> </setter.value> </setter> </style>
the problem radbutton
not fire delegatecommand
of mainviewmodel
. have same button in usercontrol out of radgridview
, works fine.
please can tell me how can fix problem of radbutton
in radgridview
?
thanks lot best regards rr
ps: have simple project, can't attach it
the reason why happening binding on radbutton trying find addtabcommand on datacontext of button, not parent window.
to fix this, advise setting style inside window's resources, , instead of using this:
command="{binding addtabcommand}"
give window name, , use this:
command="{binding elementname=windowname, path=datacontext.addtabcommand}"
Comments
Post a Comment