Comments (17)
I have removed the lines
https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/master/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Menu.xaml#L230
and
https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/master/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Menu.xaml#L236
I have found no unexpected visual behavior in my application that got introduced by removing those two lines
from materialdesigninxamltoolkit.
Thank you very much for your reply. I'll try to investigate this further.
from materialdesigninxamltoolkit.
I have added your code to MenuAndToolBars.xaml and the following gif shows the behavior
from materialdesigninxamltoolkit.
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.
from materialdesigninxamltoolkit.
This line expects there to be a UserControl of .... due to the CompositeCollection.
Yes, unfortunately this is true
There might be some confusion about MenuBase:
No, it was clear that myBaseMenu
as ResourceKey has nothing to do withx:Type MenuBase
.
I just wantet to state why I have such a situation
from materialdesigninxamltoolkit.
@michaelmairegger Is there a particular reason you choose the ContextMenu.ItemsSource
property instead of just the XAML below?
The ItemsSource
property is often used when the objects you have are not UI elements, and a DataTemplate
is the used to visualize these "data" items. In your case, you are putting actual UI elements into the collection. I suspect this is also the reason for the binding error. Without having verified my theory, I would assume that the MenuItem
instances you put in the CompositeCollection
are not (at least not initially) part of the visual tree, but only the logical tree, and the binding which attempts to travel up the visual tree to find the root ContextMenu
(i.e. MenuBase
) then ends up failing.
<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>
from materialdesigninxamltoolkit.
@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>
from materialdesigninxamltoolkit.
@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
from materialdesigninxamltoolkit.
Unfortunately it is not working. I created a workaround by modifying the style and removing the two lines that created the issue
from materialdesigninxamltoolkit.
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?
from materialdesigninxamltoolkit.
@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 master
branch to test this bug.
from materialdesigninxamltoolkit.
Ok thanks for the information. I will try it on my end, and add a branch to my fork that replicates the issue.
from materialdesigninxamltoolkit.
This only seems to be an issue when used with a ContextMenu
, a regular Menu
does not give this error. I'm not sure why at this moment.
UPDATE: I think it has to do with the AdornerDecorator
in the ControlTemplate of the default style for context menu. Will test tomorrow.
from materialdesigninxamltoolkit.
Thanks. I think the main issue will be that CompositeCollection is not part of the visual tree
from materialdesigninxamltoolkit.
Yes, this indeed seems to be the case. The AdornerDecorator
is not the problem. I tested this.
I don't know if we will be able to resolve this as the default style for MenuItem
is expecting a MenuBase
usercontrol as its parent somewhere in the tree. I'm trying to get myself familiar with CompositeCollection
, but its the first time that I work with this class.
from materialdesigninxamltoolkit.
<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>
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 Base
menu
from materialdesigninxamltoolkit.
Yes, I understand what you are trying to do. My last comment was explaining why this is happening.
There might be some confusion about MenuBase
:
- In your example, you are using
BaseMenu
as a name for a resource - In my comment
MenuBase
is an abstract class thatMenu
andContextMenu
both inherit
To be clear, this explanation above is not the issue.
The issue is, as you mentioned, that CompositeCollection
is not a part of the Visual Tree. That is why following XAML line defined in the MaterialDesignMenuItem
style is failing:
<Setter Property="Height" Value="{Binding Path=(wpf:MenuAssist.TopLevelMenuItemHeight), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuBase}}" />
This line expects there to be a UserControl
of class MenuBase
to be in the Ancestors of the MenuItem
; which is not the case due to the CompositeCollection
.
from materialdesigninxamltoolkit.
Related Issues (20)
- ColorReference does not contain any color HOT 1
- Event Handler Leak on every button click - System.Windows.VisualStateManager+<>c__DisplayClass12_0 HOT 3
- XamlParseException: InverseBoolToVisConverter - commit (#3515)
- SmartHint is clipped when FloatingScale > 1
- AutoSuggestBox crashes (demo) application
- DatePicker / TimePicker hover effect is lost when hovering calendar/time button
- SplitButton style HOT 4
- cant apply any style HOT 1
- Update the wiki: Broken Links in Project Wiki HOT 3
- MVVM使用SnackbarMessageQueue导致不能被GC(内存泄露) HOT 1
- Suggest adding a multi selection combo box control HOT 1
- Demo, Information Links URL not correct HOT 1
- Using <WindowChrome.WindowChrome> on WPF Window turns floating hints background black HOT 8
- The Dark Theme cannot be displayed properly HOT 3
- WPF UI Freezes after resuming from lock screen when window contains a Slider HOT 1
- ScrollViewer Padding HOT 2
- Disabled style of the TextBox and ComboBox are different HOT 4
- TreeListView: ArgumentOutOfRange expanding items via the data context HOT 1
- ToggleButton throws Exception with error on ValidatesOnDataErrors/IDataErrorInfo
- New colors don't match old v4.x colors
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from materialdesigninxamltoolkit.