Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Utilizing CompositeCollection for AnchorableContextMenu is not possible due to bindings resolving to wrong context #200

Closed
X39 opened this issue Sep 7, 2020 · 3 comments

Comments

@X39
Copy link

X39 commented Sep 7, 2020

Trivia

Changing from xceed AvalonDock to this, i am facing some issues i am right now tracking down.
One of them was, that the custom-context-menu extensions no longer have been working.
After investigating further, i found out that this is being caused by the ContextMenu no longer having the correct DataContext set.

Steps to Reproduce

  1. Setup
    0.1 Create some WPF project and setup AvalonDock inside of it
    0.2 Add an Anchorable
    0.3 Add some DataContext that exposes some bindable ICollection<MenuItem>
    0.4 Add any demo MenuItem inside of that collection
    0.5 Bind to that property inside AnchorableContextMenu, using a CompositeCollection
  2. Open the ContextMenu of the Anchorable
  3. Click one of the demo items

Expected

  1. The demo items appear inside of the collection

Actual

  1. The demo items did not appear inside of the collection

Notes

If the CompositeCollection is removed and the property is bound to directly using <ContextMenu ItemsSource="{Binding DataContext.Model.MenuItems}"/>, the binding gets resolved proper though.

Attachements

<ad:DockingManager.AnchorableContextMenu>
    <ContextMenu>
        <ContextMenu.Resources>
            <CollectionViewSource x:Key="MenuItems" Source="{Binding DataContext.Model.MenuItems}"/>
        </ContextMenu.Resources>
        <ContextMenu.ItemsSource>
            <CompositeCollection>
                <MenuItem Header="Unbound Menu Item"/>
                <Separator/>
                <CollectionContainer Collection="{Binding Source={StaticResource MenuItems}}"/>
            </CompositeCollection>
        </ContextMenu.ItemsSource>
    </ContextMenu>
</ad:DockingManager.AnchorableContextMenu>
System.Windows.Data Warning: 40 :
BindingExpression path error: 'DataContext' property not found on 'object' ''MainWindowDataContext' (HashCode=55769358)'.
BindingExpression:Path=DataContext.Model.MenuItems;
DataItem='MainWindowDataContext' (HashCode=55769358);
target element is 'CollectionViewSource' (HashCode=42781795);
target property is 'Source' (type 'Object')
@Dirkster99
Copy link
Owner

Hi, thank you for your detailled report but I am not sure what I should do with it, yet :-(

since I have no demo project showing the behavior you report above and I am also not sure where you want to apply the AnchorableContextMenu XAML tag fix shown in the Attachements section above?

Could you please re-test this issue as we have fixed an issue in VS2013 with the ContextMenu in Version 4.4? Thank you.

@X39
Copy link
Author

X39 commented Sep 23, 2020

Will do tomorrow. If you could tell me where to Look theese Kind of things up (afterall.. The project is rather complex) I will also gladly fix the stuff and create a PR 😉 probably will find plenty more problematic spots due to the recent move from xceed to this.

Will append the corresponding full file tomorrow too.

@Dirkster99
Copy link
Owner

I am not sure what you mean by 'these kind of things' - the project is complex I know but it should be possible to describe an issue such that it is possible to verify a problem and right now I am not even able to verify the issue since the demo projects in the repository work fine and do not seem to exhibit the binding issue you report. So, to enable me to verify/understand an issue you could either:

  1. prepare a demo app, zip its source code and attach it to this issue (via drag & drop) or you could
  2. fork the repository and adjust any demo app such that your issue can be verified.

From there I just need to understand what fix (if you already have any) needs to be applied where. The best way for this is to author a pull-request - here is a short description of a pull request I've written earlier but you usually find tons of content when you search for it on the Internet.

You could avoid a pull request, if your suggested change is simple and easy to implement by refering to an existing code portion of code in the master branch of this repository and simply saying I suggest to fix this by replacing it with 'xyz' (see this for details).

Lastly, I've tried to collect a lot of information on the architecture of this project in the Wiki section - please refer to this for a basic understanding. Let me know if you are missing information on anything else and I'll try to chase it up for you if I can, thanx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants