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

error when adding context menu on tree view item #290

Closed
b3b00 opened this issue Sep 7, 2023 · 3 comments
Closed

error when adding context menu on tree view item #290

b3b00 opened this issue Sep 7, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@b3b00
Copy link

b3b00 commented Sep 7, 2023

Hello,

I am trying to add a context menu on a tree view node :

<TreeView ItemsSource="{Binding Items}" >
        <TreeView.ItemTemplate>
            <TreeDataTemplate ItemsSource="{Binding Items}" x:DataType="minimalTvCtxMenu:Node">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Label}">
                        <TextBlock.ContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Copy label."
                                          Command="{Binding Say}"
                                          CommandParameter="{Binding .}" />
                            </ContextMenu>
                        </TextBlock.ContextMenu>
                    </TextBlock>
                </StackPanel>
            </TreeDataTemplate>
        </TreeView.ItemTemplate>
    </TreeView>

full example is here : b3b00/avaloniaMaterialContextMenu

When using material theme, right clicking a node causes an exception :
When switching to fluent theme the menu opens correctly.

System.InvalidOperationException: ControlTemplate styles cannot contain multiple template selectors.
   at Avalonia.Styling.Selector.ValidateNestingSelector(Boolean inControlTheme)
   at Avalonia.Styling.Style.SetParent(StyleBase parent)
   at Avalonia.Styling.StyleChildren.InsertItem(Int32 index, IStyle item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at Avalonia.Styling.StyleBase.Add(IStyle style)
   at CompiledAvaloniaXaml.!AvaloniaResources.XamlClosure_181.Build(IServiceProvider )
   at Avalonia.Markup.Xaml.XamlIl.Runtime.XamlIlRuntimeHelpers.<>c__DisplayClass1_0`1.<DeferredTransformationFactoryV2>b__0(IServiceProvider sp)
   at Avalonia.Controls.ResourceDictionary.TryGetValue(Object key, Object& value)
   at Avalonia.Controls.ResourceDictionary.TryGetResource(Object key, ThemeVariant theme, Object& value)
   at Avalonia.Markup.Xaml.MarkupExtensions.StaticResourceExtension.ProvideValue(IServiceProvider serviceProvider)
   at CompiledAvaloniaXaml.!AvaloniaResources.XamlClosure_183.Build(IServiceProvider )
   at Avalonia.Markup.Xaml.XamlIl.Runtime.XamlIlRuntimeHelpers.<>c__DisplayClass1_0`1.<DeferredTransformationFactoryV2>b__0(IServiceProvider sp)
   at Avalonia.Controls.ResourceDictionary.TryGetValue(Object key, Object& value)
   at Avalonia.Controls.ResourceDictionary.TryGetResource(Object key, ThemeVariant theme, Object& value)
   at Avalonia.Controls.ResourceDictionary.TryGetResource(Object key, ThemeVariant theme, Object& value)
   at Avalonia.Styling.Styles.TryGetResource(Object key, ThemeVariant theme, Object& value)
  ...

Is material avalonia compatible with tree view context menu's ? is there something more to do to make it ok ?

Thanks for all your great work.

@SKProCH SKProCH added the bug Something isn't working label Sep 7, 2023
@SKProCH
Copy link
Collaborator

SKProCH commented Sep 7, 2023

Hello

Seems like this is the bug with ContextMenu. I'll take a look.

@SKProCH SKProCH closed this as completed in 7e36c67 Sep 7, 2023
@SKProCH
Copy link
Collaborator

SKProCH commented Sep 7, 2023

@b3b00

Can you test the latest nightly?

@b3b00
Copy link
Author

b3b00 commented Sep 8, 2023

@SKProCH , great jobs it's working. thanks for your real quick fix 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants