ARTICLE

Interactive Menu using ListBox in WPF

Posted by Diptimaya Patra Articles | WPF July 28, 2010
In this article we will see how we can make use of a ListBox control to look like a menu.
Reader Level:
Download Files:
 

Introduction

In this article we will see how we can make use of a ListBox control to look like a menu.

1.gif
 
Creating a WPF Project

Fire up Visual Studio 2010, create a WPF Application, and name it as ListBoxMenuSample.

2.gif

First thing we need to add is a ListBox.

Then we would create a class which would have the following properties.

3.gif 

As you see in the above class, we have two Image Uri, this is because when we would mouse hover an item then the large image should be displayed.

We can achieve this by simply modifying the ListBoxItem template and the ItemsPanelTemplate.

Let's start with the ListBoxItem customization.

4.gif
 
Then we need to customize the ItemsPanelTemplate.

5.gif 

The above xaml code is for the customization of the ListBoxItem and ItemsPanelTemplate.

Before running the application let's create some sample data.

6.gif 

Now run the application, and you can see the template is working fine.

7.gif 

Now, with the help of Trigger we can apply to the ControlTemplate and we can achieve the mouse over functionality.

8.gif 

Add the above Trigger for the ControlTemplate of the ListBoxItem. Remember the values are fully dependent on the image's size. Such as if your image has some big padding then you need to reduce, otherwise you may not achieve your target requirement.

Now, let's run the application once again and you would see the Mouse over effect.

9.gif 

Hope this article helps.

Login to add your contents and source code to this article
post comment
     

how i can make it with wrappanel i'm try but i can't :(

Posted by sayed ahmed May 29, 2011

Sorry jean, i was too busy, but i'll make an example using this code and add here. regards.

Posted by Franks feat Dec 09, 2010

Sorry about bugging you like this, I'm new at all of this, so I am a noob.  But if we are looking at the code above, author's code, how would I apply the click event in there.

Really sorry, I'm actually a first year student and we have only done VB

Posted by Jean Engelbrecht Dec 04, 2010

For each button on you window you shuld add a evend o XAML declaration

<Button  MouseRightButtonDown="Button_MouseRightButtonDown"
Click="Button_Click" UseLayoutRounding="True">

and in the code behind

private void Button_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Your CODE GOES HERE
        }


Posted by Franks feat Dec 03, 2010

How do you program each button to do it's own thing

Posted by Jean Engelbrecht Dec 03, 2010
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter