c# - wpf : Bind to a control in another xaml file -


i have main.xaml file. in main.xaml file, refer listbox in xaml file. call using view:layoutviewlist

in main.xaml file, there button. button enable when listbox selected. elementname=view.layoutviewlist.layoutlistbox not working. thank much

button isenabled="{binding elementname=view:layoutviewlist.layoutlistbox, path=selecteditems.count}"  

binding error :

system.windows.data error: 4 : cannot find source binding reference 'elementname=view:layoutviewlist.layoutlistbox'. bindingexpression:path=selecteditems.count; dataitem=null; target element 'button' (name=''); target property 'isenabled' (type 'boolean') system.windows.data error: 4 : cannot find source binding reference 'elementname=view:layoutviewlist.layoutlistbox'. bindingexpression:path=selectedindex; dataitem=null; target element 'button' (name=''); target property 'notarget' (type 'object') 

you need use relativesource binding if view binding child of mainview file. try this:

<button isenabled="{binding datacontext.selecteditems.count, relativesource={     relativesource ancestortype={x:type yourprefix:mainview}}" /> 

this binding refers count property of object exposed selecteditems property in object set datacontext of usercontrol or window named mainview.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -