Search code examples
c#uwpuwp-xamlwinui

Add slider control to menu flyout in UWP


I am trying to embed a slider control as a menu item in UWP:

Context menu with trackbar

This can be done with Windows Forms' ToolStripControlHost class and, on WPF, by just adding a Slider directly inside a MenuItem in the XAML.

In UWP, adding a Slider inside a MenuFlyoutSubItem does not work as the MenuFlyoutSubItem expects a MenuFlyoutItemBase.

Writting a SliderMenuFlyoutItem that extends MenuFlyoutSubItem seems like the logical approach, however I am not sure how to draw the Slider and handle the mouse events in this case.

Any pointers on how this can be achieved?

Thanks


Solution

  • You can try to use a Flyout instead of a MenuFlyout

     <Flyout>
         <StackPanel>
             <MenuFlyoutItem Text="Item1"/>
             <MenuFlyoutItem Text="Item2"/>
             <Slider Width="100" Maximum="100" Minimum="0"/>
             <MenuFlyoutSeparator />
             <MenuFlyoutItem Text="Item3"/>
         </StackPanel>              
     </Flyout>