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

MenuFlyout ItemTepmplate still not applied #10626

Closed
FG-rgb opened this issue Mar 10, 2023 · 0 comments · Fixed by #10836
Closed

MenuFlyout ItemTepmplate still not applied #10626

FG-rgb opened this issue Mar 10, 2023 · 0 comments · Fixed by #10836
Assignees
Labels

Comments

@FG-rgb
Copy link

FG-rgb commented Mar 10, 2023

MenuFlyout ItemTepmplate does not gets applied:
With Avalonia 0.10.18 the items are plain shown in UI as ToString()

With Avalonia 11.0.0-preview5 it is complete broken and nothing is shown:
[Binding]Error in binding to 'Avalonia.Controls.MenuFlyout'.'Items': 'Null value in expression '{empty}' at ''.'(MenuFlyout #5560998)

My Window xaml looks like this:

<Button Content="Testen">
    <Button.Flyout>
	    <MenuFlyout Placement="Left" Items="{Binding Path=TestItems,Mode=OneWay}">
		    <MenuFlyout.ItemTemplate>
			    <DataTemplate>
				    <TextBlock Text="{Binding Path=Name,Mode=OneWay}" />
			    </DataTemplate>
		    </MenuFlyout.ItemTemplate>
	    </MenuFlyout>
    </Button.Flyout>
</Button>

And the ViewModel looks like this:

public record class TestItem(string Name, string Info);

public class MainWindowViewModel
{
    public MainWindowViewModel()
    {
        TestItems = new ObservableCollection<TestItem>
        {
            new TestItem("Hallo", "Hallo Welt"),
            new TestItem("Bla", "Hallo Welt"),
            new TestItem("Blubb", "Hallo Welt"),
            new TestItem("Etwas mehr Text", "Hallo Welt"),
            new TestItem("Hallo Ihr da", "Hallo Welt")
        };
    }

    public ObservableCollection<TestItem> TestItems { get; }

Desktop (please complete the following information):

  • OS: Windows 10 Pro 21H2 64 Bit
@FG-rgb FG-rgb added the bug label Mar 10, 2023
@grokys grokys self-assigned this Mar 29, 2023
grokys added a commit that referenced this issue Mar 29, 2023
grokys added a commit that referenced this issue Mar 29, 2023
- `MenuItem` is a `HeaderedSelectingItemsControl` not a `HeaderedItemsControl` so  need to separate logic for that case when preparing items
- Added `HeaderTemplate` to `HeaderedSelectingItemsControl `
- Tweaked logic for selecting header templates: parent's `ItemTemplate` should be used if set (cross-checked with WPF)
- Update menu templates to bind to menu item's `HeaderTemplate`

Fixes #10626
Fixes #10718
grokys added a commit that referenced this issue Mar 29, 2023
grokys added a commit that referenced this issue Mar 29, 2023
- `MenuItem` is a `HeaderedSelectingItemsControl` not a `HeaderedItemsControl` so  need to separate logic for that case when preparing items
- Added `HeaderTemplate` to `HeaderedSelectingItemsControl `
- Tweaked logic for selecting header templates: parent's `ItemTemplate` should be used if set (cross-checked with WPF)
- Update menu templates to bind to menu item's `HeaderTemplate`

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

Successfully merging a pull request may close this issue.

2 participants