Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:38:43+00:00 2026-06-11T17:38:43+00:00

I’m creating an app in WPF. I included a Systray icon using System.Windows.Forms.NotifyIcon the

  • 0

I’m creating an app in WPF.

I included a Systray icon using “System.Windows.Forms.NotifyIcon”

the code looks like:

// Create WinForm notify icon
m_NotifyIcon = new System.Windows.Forms.NotifyIcon();
m_NotifyIcon.Icon = Properties.Resources.rocket;
m_NotifyIcon.Visible = true;
// Default Balloon title
m_NotifyIcon.BalloonTipTitle = "Greatest App ever";
m_NotifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu();

// Append default menu items
List<MenuItem> itemList = new List<MenuItem>();
itemList.Insert(0, new MenuItem("Exit", OnExit_Click));
itemList.Insert(0, new MenuItem("-"));
itemList.Insert(0, new MenuItem("Refresh", RefreshConsoleList));
itemList.Insert(0, new MenuItem("Filter: \"" + (String.IsNullOrEmpty(m_Filter) ? "NONE" : m_Filter) + "\"", ChangeFilter_Click));
itemList.Insert(0, new MenuItem("-"));
m_NotifyIcon.ContextMenu.MenuItems.AddRange(itemList.ToArray());

the result looks like this:

Before Refreshing

In the case of the refresh, my application will get a lot of entries, then append these entries in the ContextMenu, the menu will looks like this:

Overflow of MenuItem

As you can see, there is too many MenuItem and because of the overflow, 2 arrows will be displayed (Top and Bottom of the ContextMenu)

Now if the user wants to Exit the application, he have to scroll down, then click on Exit.
If the list is really big, it can annoy the user.

To avoid this, I want to display the ContextMenu already scrolled to the bottom when it pop up (the first MenuItem is visible)

But I didn’t find any event or control to use to Scroll Down programmatically the ContextMenu.

Is it possible to do?

Regards

Yves Desgraupes


PS: I was unable to directly post the Images because of my reputation (it’s my first post), and post more than 2 links.

the third exemple is here:

yves.desgraupes.free.fr/shared/ContextMenu_OverflowScroll.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:38:44+00:00Added an answer on June 11, 2026 at 5:38 pm

    What you could do is use a WPF implementation of the NotifyIcon.

    • http://wpfcontrib.codeplex.com/wikipage?title=NotifyIcon&referringTitle=Home

    Then you could have a WPF menu, and have more control over how you implement the behaviour you want in the menu.

    So you could define a Template for the ContextMenu and get access to the ScrollViewer within the ContextMenu template and then call ScrollToEnd() on it.

    Here’s an example that shows how to create a WPF context menu that when it starts up is scrolled to the end. You can use this in your WPF NotifyIcon. Right click on the Button to see the contextmenu.

    Note I’ve provided it as a starting point….you may be able to improve the code..reduce some repetitions…but it works….e.g…to get around a glitch when the menu is first displayed it doesn’t scroll to the end I had to trap the SizeChanged event.

    <Window x:Class="WpfApplication15.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <Style TargetType="{x:Type ContextMenu}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ContextMenu}">
                            <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
    BorderThickness="{TemplateBinding BorderThickness}">
                                <ScrollViewer x:Name="scrollviewer"
    Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"
    CanContentScroll="True" >
                                    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Margin="{TemplateBinding Padding}"
    KeyboardNavigation.DirectionalNavigation="Cycle"/>
                                </ScrollViewer>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
        <Grid>
            <Button x:Name="mybutton">
                <Button.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Test1"/>
                    </ContextMenu>
                </Button.ContextMenu>
                Test Button
            </Button>       
        </Grid>
    </Window>
    

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Windows.Controls.Primitives;
    
    namespace WpfApplication15
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public static T FindVisualChild<T>(DependencyObject depObj) where T : DependencyObject
            {
                if (depObj != null)
                {
                    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                    {
                        DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                        if (child != null && child is T)
                        {
                            return (T)child;
                        }
    
                        T childItem = FindVisualChild<T>(child);
                        if (childItem != null) return childItem;
                    }
                }
                return null;
            }
    
            public MainWindow()
            {
                InitializeComponent();
    
                ContextMenu contextmenu = mybutton.ContextMenu;
    
                // Add 100 more items
    
                for (int i = 2; i <= 100; i++)
                {
                    MenuItem mi = new MenuItem();
                    mi.Header = "Item" + i.ToString();
    
                    contextmenu.Items.Add(mi);
                }
    
                contextmenu.SizeChanged += new SizeChangedEventHandler(contextmenu_SizeChanged);
                contextmenu.Loaded += new RoutedEventHandler(contextmenu_Loaded);
    
                mybutton.ContextMenuOpening += new ContextMenuEventHandler(mybutton_ContextMenuOpening);
            }
    
            void contextmenu_SizeChanged(object sender, SizeChangedEventArgs e)
            {
                ContextMenu contextmenu = mybutton.ContextMenu;
    
                ScrollViewer sv = FindVisualChild<ScrollViewer>(contextmenu);
                if (sv != null)
                {
                    sv.ScrollToEnd();
                }
            }
    
            void contextmenu_Loaded(object sender, RoutedEventArgs e)
            {
                ContextMenu contextmenu = mybutton.ContextMenu;
    
                ScrollViewer sv = FindVisualChild<ScrollViewer>(contextmenu);
                if (sv != null)
                {
                    sv.ScrollToEnd();
                }
            }
    
            void mybutton_ContextMenuOpening(object sender, ContextMenuEventArgs e)
            {
                ContextMenu contextmenu = mybutton.ContextMenu;
                ScrollViewer sv = FindVisualChild<ScrollViewer>(contextmenu);
                if (sv != null)
                {
                    sv.ScrollToEnd();
                }
            }
        }
    }
    

    On a side note….you might want to limit the height of the ContextMenu…by setting MaxHeight…demo here.

    <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
      <Grid>  
      <Button>
      <Button.ContextMenu>
      <ContextMenu MaxHeight="100">
      <MenuItem Header="Test1"/>
      <MenuItem Header="Test2"/>
      <MenuItem Header="Test3"/>
      <MenuItem Header="Test4"/>
      <MenuItem Header="Test5"/>
      <MenuItem Header="Test6"/>
      <MenuItem Header="Test7"/>
      <MenuItem Header="Test8"/>
      <MenuItem Header="Test9"/>
      </ContextMenu>
      </Button.ContextMenu>
      Test Button</Button>
      </Grid>
    </Page>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.