Caliburn.Micro action binding between different Visual Trees

155 Views Asked by At

I'm using WPFToolkit's DropDownButton to display a small editor containing a button that's used to clear the editor's fields via a simple method in the VM. The method only needs to be invoked and there are no parameters that need to be passed to it.

The main issue is that the DropDownButton uses a popup to display its DropDownContent (the editor), and the Popup resides on a different VisualTree. I can't seem to reach the original tree in order to invoke the method using Action.TargetWithoutContext.

I've seen solutions for this sort of issue but mostly surrounding ContextMenus and using

Action.TargetWithoutContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}"

I've tried changing the Binding Path of the TargetWithoutContext to the parent DropdownButton (naming them, of course), tried using AncestorType and different RelativeSources but my knowledge in Caliburn.Micro or debugging these sort of issues is unfortunately not extensive enough to tackle this issue.

The View, omitting any irrelevant controls and styling:

        <ListView x:Name="FIS"
                  ItemsSource="{Binding}"
                  SelectedItem="{Binding Path=FISSelected, Mode=TwoWay}"
                  dd:DragDrop.IsDragSource="True">

            <ListView.View>
                <GridView>

                    <GridViewColumn Header="ColumnHeader">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <wpfTool:DropDownButton>
                                    <wpfTool:DropDownButton.Content>
                                        <TextBlock Text="{Binding}">
                                    </wpfTool:DropDownButton.Content>
                                    <wpfTool:DropDownButton.DropDownContent>
                                        <StackPanel>
                                            <Label/>
                                            <DockPanel>
                                                <Button x:Name="ClearFields" Content="Clear"
                                                        cal:Message.Attach="[Event Click] = [Action Clear]"
                                                        cal:Action.TargetWithoutContext="???"/>
                                            </DockPanel>
                                        </StackPanel>
                                    </wpfTool:DropDownButton.DropDownContent>
                                </wpfTool:DropDownButton>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                </GridView>
            </ListView.View>

        </ListView>

So far I'm getting a System.Exception: 'No target found for method INDClear.' error when invoking the method:

System.Windows.Data Error: 4 : Cannot find source for binding with reference [TargetWithoutContext reference parameters]. An unhandled exception of type 'System.Exception' occurred in WindowsBase.dll No target found for method Clear.

0

There are 0 best solutions below