Context Flyouts work in very few and very specific situations and nowhere else.
Description
FlyoutBase.ContextFlyouts (right click menus) only appear to work in very specific and inflexible situations.
I have been attempting to implement them in collection views and built a sample App to show 4 different ways that should be working (I believe) but do not.
Every implementation that involves commands, does not work, only the "clicked" events work. Even the "clicked" events have their own problems, as when you try to use the "clicked" events with a Selector class, the program will not compile. In each situation I added a button hooked up the exact same way, to show you that this method of DataBinding does indeed work. The buttons in each collection, whether through a selector or not, all call the command correctly.
I have tried every implementation of RelativeSource sources I can think of but none appear to work.
Steps to Reproduce
Run the App and play with the buttons to see what does and does not respond. Each square surrounding each button has a ContextFlyout attached that you can right click and use. The description of each is above each column when you run the app.
Link to public reproduction project repository
https://github.com/ehoward0018/ContextMenuCommandBinding
Version with bug
7.0.49
Last version that worked well
Never
Affected platforms
Windows, I was not able test on other platforms
Affected platform versions
net7.0 Windows 10.0.19041.0
Did you find any workaround?
Not as of yet.
Relevant log output
No response
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
So is this the intended usability of Context Flyouts, or should they indeed be operating through Selectors and DataTemplates?
This is indeed a problem since many of the uses for context menu involve collectionView Items.
@ehoward0018 Maybe as a hack, you can call the ViewModel Command from the Clicked event handler. I haven't been able to do this because my Clicked event handler is in a contentView and my ViewModel's Constructor is injected... unless someone knows how to get around this and I'd love to know how. Thanks.
@BillyMartin1964 There are a couple different hacks I have tried, but they are are all messy, and most importantly, do not work with Selectors. You cannot currently edit the right click menus, but sometimes in a CollectionView I want to have different types of right click menus based off the status of said item. This actually works, and will bring up different context menus based on the selector, but there is no way currently I can find to actually make those different buttons on the selector call anything.
Again, visually everything appears to be working, but the buttons themselves are not usable.
There is a workaround for collections!
CommandParameter="{Binding .}" Command="{Binding Source={x:Reference Insert x:Name of the page, Path=BindingContext.MyCommand}"
There are still major problems with this, and the baseline use case still needs to be fix. The main issue is that this makes the code far less reusable unless you name every page the same.
Verified this issue with Visual Studio Enterprise 17.9.0 Preview 4. Still repro on ehoward0018/ContextMenuCommandBinding: Bug report for .net maui (github.com)