-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Binding issues with ContextMenu and CompositeCollection #3464
Comments
@michaelmairegger Is there a particular reason you choose the The <ContextMenu>
<MenuItem Header="Hello World" />
<MenuItem Header="Clickety Click">
<MenuItem Header="Clackety Clack" />
</MenuItem>
</ContextMenu> or <ContextMenu>
<ContextMenu.Items>
<MenuItem Header="Hello World" />
<MenuItem Header="Clickety Click">
<MenuItem Header="Clackety Clack" />
</MenuItem>
</ContextMenu.Items>
</ContextMenu> |
@nicolaihenriksen Yes there is a reason. I have a "BaseMenu" that contains multiple MenuItems that are reused within many views, e.g. <UserControl.Resources>
<CompositeCollection x:Key="BaseMenu">
<MenuItem Header="Add" />
<MenuItem Header="Edit" />
<MenuItem Header="Delete" />
</CompositeCollection>
</UserControl.Resources>
<ContextMenu>
<ContextMenu.ItemsSource>
<CompositeCollection >
<CollectionContainer Collection="{StaticResource BaseMenu}" />
<Separator />
<MenuItem Header="Hello World" />
<MenuItem Header="Clickety Click">
<MenuItem Header="Clackety Clack" />
</MenuItem>
</CompositeCollection>
</ContextMenu.ItemsSource>
</ContextMenu> |
@michaelmairegger - try this: <ContextMenu>
<ContextMenu.ItemsSource>
<CompositeCollection >
<CollectionContainer Collection="{Binding Source={StaticResource BaseMenu}}" /> <!-- Note the binding -->
<Separator />
<MenuItem Header="Hello World" />
<MenuItem Header="Clickety Click">
<MenuItem Header="Clackety Clack" />
</MenuItem>
</CompositeCollection>
</ContextMenu.ItemsSource>
</ContextMenu> See here: https://stackoverflow.com/a/40147645 |
Unfortunately it is not working. I created a workaround by modifying the style and removing the two lines that created the issue |
Could you tell us which lines? |
I have removed the lines I have found no unexpected visual behavior in my application that got introduced by removing those two lines |
Thank you very much for your reply. I'll try to investigate this further. |
@michaelmairegger I can't replicate the behavior you're reporting. I added this XAML code in the demo app in search of replicating this: <smtx:XamlDisplay Margin="0,0,16,16" UniqueKey="menus_6">
<smtx:XamlDisplay.Resources>
<CompositeCollection x:Key="BaseMenu">
<MenuItem Header="Add" />
<MenuItem Header="Edit" />
<MenuItem Header="Delete" />
</CompositeCollection>
</smtx:XamlDisplay.Resources>
<TextBox Width="256" Text="With CompositeCollection (see issue #3464)">
<TextBox.ContextMenu>
<ContextMenu>
<ContextMenu.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{StaticResource BaseMenu}" />
<Separator />
<MenuItem Header="Hello World" />
<MenuItem Header="Clickety Click">
<MenuItem Header="Clackety Clack" />
</MenuItem>
</CompositeCollection>
</ContextMenu.ItemsSource>
</ContextMenu>
</TextBox.ContextMenu>
</TextBox>
</smtx:XamlDisplay> Disclaimer: I'm using the |
Ok thanks for the information. I will try it on my end, and add a branch to my fork that replicates the issue. |
Apologies, my mistake, I was expecting a more blocking runtime exception. Now, I see the same problem you are seeing. I'll look into what the effect is of removing those lines you mentioned. |
This only seems to be an issue when used with a UPDATE: I think it has to do with the |
Thanks. I think the main issue will be that CompositeCollection is not part of the visual tree |
Yes, this indeed seems to be the case. The I don't know if we will be able to resolve this as the default style for |
I came across this issue because of the situation that I do not want to define the same menu structure over and over again. Therefore I have created a |
Yes, I understand what you are trying to do. My last comment was explaining why this is happening. There might be some confusion about
To be clear, this explanation above is not the issue. The issue is, as you mentioned, that <Setter Property="Height" Value="{Binding Path=(wpf:MenuAssist.TopLevelMenuItemHeight), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuBase}}" /> This line expects there to be a |
Yes, unfortunately this is true
|
Bug explanation
I have XAML Binding Failures with MenusAndToolBars.xaml if I change the lines https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/master/MainDemo.Wpf/MenusAndToolBars.xaml#L355-L360 with the follwogin content:
saying:
Do you have an idea how to fix this issue?
Version
4.9.0
The text was updated successfully, but these errors were encountered: