How to make it scrollable?

Feb 23, 2012 at 1:48 PM
I have downloaded and used the SL4PopupMenu and its really great.
But codeplex says it's scrollable, however i cannot find out how to make it scrollable, i tried adding ScrollViewer to ItemsPresenters but it didn't work, here is what i did:
                            <ScrollViewer VerticalScrollBarVisibility="Auto" Height="80" MaxHeight="50">
                                <ItemsPresenter Grid.ColumnSpan="2" Margin="{TemplateBinding Padding}"/>
                            </ScrollViewer>
so can any one help me?
Coordinator
Feb 24, 2012 at 5:30 PM

Thanks for your appreciation.

Have you tried it with a ListBox instead?

This should work fine:

<ListBox ScrollViewer.VerticalScrollBarVisibility="True" >
...
<ListBox/>

Feb 26, 2012 at 2:02 PM
Edited Feb 26, 2012 at 2:04 PM

Dear ZiadJ,

Thanks for your help , i now have a new requirement i wanted to generate the popup menu dynamically, so i did the following

  subsubmenu.ItemsControl.MaxHeight = 250; 

  subsubmenu.Width = 150;

 

that made the scroll bar appear, but generated null reference exception upon scrolling at line [this.Container.IsEnabled = this.IsEnabled;] in code snippet      

 

                if (this.Container != null) // Don't bother calling synchContainerState if the container does not yet exist since it will eventually be called in OnApplyTemplate.
                {
                    this.Container.IsEnabled = this.IsEnabled; // Sync the container state.

                    this.Container.Dispatcher.BeginInvoke(delegate
                    {
                        this.Container.IsEnabled = this.IsEnabled; // Sync the container state.
                    });
                }



So i commented these lines of codes and everything went fine
Is what i did right and this won't generate further bugs in the future? Or can you help me with another workaround?
Thanks in advance

Coordinator
Feb 27, 2012 at 1:26 AM
Edited Feb 27, 2012 at 1:31 AM

That's weird because the code starts with if (this.Container != null) which is there to make sure that the value is not null beforehand.

I'm missing something here. Can you give me more details on which property is null and on which line?

Otherwise this shouldn't introduce any major bugs. At worst the menu items might not go into disabled mode when IsEnabled is false.

Feb 27, 2012 at 9:06 AM

Hi ZiadJ,

The null reference exception appears in the underlined red line

                if (this.Container != null) // Don't bother calling synchContainerState if the container does not yet exist since it will eventually be called in OnApplyTemplate.
                {
                    this.Container.IsEnabled = this.IsEnabled; // Sync the container state.

                    this.Container.Dispatcher.BeginInvoke(delegate
                    {
                       this.Container.IsEnabled = this.IsEnabled; // Sync the container state.
                    });
                }
and the null object is [this.Container]

that exception appears only upon scrolling the context menu.

Thanks for your help

Coordinator
Feb 27, 2012 at 1:36 PM
Edited Feb 27, 2012 at 1:44 PM

Ok thanks Mahmoud, this update should fix it:

if (this.Container != null) 
{
	var container = this.Container;

	container.Dispatcher.BeginInvoke(delegate
	{
		 container.IsEnabled = this.IsEnabled; 
	});
}

I haven't tested it myself though so I'm leaving that on you.

 

Feb 28, 2012 at 8:56 AM

Thanks Ziad that fixed it 

Regards