microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Proposal: Add binding support to MenuFlyout

Open knightmeister opened this issue 6 years ago • 8 comments

Proposal: [Add binding support to MenuFlyout

Summary

Presently items in a flyout need to be defined ahead of time and cannot be bound to a collection. Add an ItemSource property and enable databinding.

Rationale

  • Supports binding to arrays for displaying menu options corresponding to an array, enumeration or similar
  • Adds consistency with most other elements which support this form of binding

Scope

Capability Priority
Developers should be able to bind a MenuFlyout to a source Must

knightmeister avatar Jul 22 '19 11:07 knightmeister

🦙 There should be a corresponding ItemTemplate called out here too. This should also apply to the MenuBar APIs.

It should also be possible to compose a menu of pieces that are static XAML and also parts driven by a list (think having a recent file list be part of a menu or sub-menu like in VS Code):

image

<muxc:MenuBar>
  <muxc:MenuBarItem Title="File">
    <MenuFlyoutItem Text="New"/>
    <MenuFlyoutSubItem Text="Open Recent...">
      <MenuFlyoutItem Text="Reopen Closed Editor"/>
      <MenuFlyoutSeparator/>
      <muxc:MenuFlyoutItemSource ItemsSource="{Binding RecentFolders}">
          <muxc:MenuFlyoutItemSource.ItemTemplate>
             <DataTemplate>
                <MenuFlyoutItem Text="{Binding FolderName}"/>
            </DataTemplate>
         </muxc:MenuFlyoutItemSource.ItemTemplate>
      </muxc:MenuFlyoutItemSource>
      <MenuFlyoutSeparator/>
      <muxc:MenuFlyoutItemSource ItemsSource="{Binding RecentFiles}">
          <muxc:MenuFlyoutItemSource.ItemTemplate>
             <DataTemplate>
                <MenuFlyoutItem Text="{Binding FileName}"/>
            </DataTemplate>
         </muxc:MenuFlyoutItemSource.ItemTemplate>
      </muxc:MenuFlyoutItemSource>
      <MenuFlyoutSeparator/>
      <MenuFlyoutItem Text="More..."/>
    </MenuFlyoutSubItem>
  </muxc:MenuBarItem>

  <muxc:MenuBarItem Title="Dynamic" ItemSource="{Binding MyMenuItems}">
     <muxc:MenuBarItem.ItemTemplate>
        <DataTemplate>
           <MenuFlyoutItem Text="{Binding ItemTitle}"/>
        </DataTemplate>
     </muxc:MenuBarItem.ItemTemplate>
  </mucx:MenuBarItem>
</muxc:MenuBar>

michael-hawker avatar Jun 04 '20 05:06 michael-hawker

@JerryNixon saw you had an article here about this topic. Though the original extension code linked to is missing?

Think you'd want to add your extension to the Windows Community Toolkit for now until the WinUI team can get to improvements in WinUI directly?

michael-hawker avatar Sep 14 '21 23:09 michael-hawker

Seems like enough people want the feature and have wanted it for a while. Anyone have an update on this?

ghost avatar Nov 04 '22 01:11 ghost

This is basic stuff. Even the simplest of applications today show recent files list. That is impossible in XAML without this.

fatichar avatar Dec 24 '22 06:12 fatichar

It's very troubling to see tickets like this. How did this get through any kind of design review?

sam-wheat avatar Mar 13 '23 13:03 sam-wheat

Any updates on this issue? i've been trying to see if i can somehow make this work, i would like to populate a list of submenuflyoutitems by binding them to an observablecollection

EugenM88 avatar Mar 09 '24 02:03 EugenM88

That's too bad!

MilkFeng avatar Mar 10 '24 15:03 MilkFeng

Really, how is something as basic that as this not implemented? This was reported in 2019, you've had 5 years to implement this basic feature... And I'd also like to know why anybody thought implementing this without binding support was a good idea.

arknu avatar Oct 14 '24 14:10 arknu

Any update on this ?

U-C-S avatar Feb 06 '25 19:02 U-C-S