wpf - Caliburn Micro Message.attach does not consider changes of datacontext -
this simplified example. have usercontrol contains "browse folder" functionality, using textbox , button. clicking button open browse-dialog, , fill in textbox.
<usercontrol x:class="myusercontrol" 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:cal="http://www.caliburnproject.org" mc:ignorable="d" d:designheight="300" d:designwidth="300"> <grid> <grid.columndefinitions> <columndefinition width="100"></columndefinition> <columndefinition width="*"></columndefinition> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="auto"></rowdefinition> </grid.rowdefinitions> <!-- folder --> <textblock>path</textblock> <dockpanel lastchildfill="true" grid.column="1"> <button dockpanel.dock="right" cal:message.attach="[event click] = [action browsehotfolder()]" content="..." horizontalalignment="left" width="25" height="25" verticalcontentalignment="center" horizontalcontentalignment="center" margin="0,0,5,0"/> <textbox text="{binding hotfolderpath, updatesourcetrigger=propertychanged, validatesonnotifydataerrors=true}" /> </dockpanel> </grid>
i have listbox contains number of objects. selected object fed usercontrol datacontext.
<window> ... <listbox itemssource="{binding items, mode=oneway}" selecteditem="{binding selecteditem}"> ... <view:myusercontrol datacontext="{binding selecteditem}" /> </window>
now, let's have 2 items in listbox , have first 1 selected. fill in "foo" in textbox of myusercontrol. select second item, , fill in "bar". databinding works fine, , both items have correct values set. if click browse button on first 1 , select folder, change textbox of first item selected path. however, if select second item, , browse folder change first item's textbox.
my guess message attach syntax not call browse action on correct item. disregards datacontext (currently selected item) , uses first one.
what can this?
i think guess correct; target used message.attach first data context bound, , not update when context changed after user selection.
we saw similar problem user controls switched in content control - fix specify cal:action.targetwithoutcontext="{binding}"
on button.
the issue mentioned here rob eisenberg: https://caliburnmicro.codeplex.com/discussions/257005
Comments
Post a Comment