Populating from code

Aug 10, 2010 at 5:28 PM

How to populate outlookbar from code, e.q.

add outlookbutton with picture

add some single line menu times with pictures as childs for created button.

Where to find sample code for this ?

Andrus.

 

Coordinator
Aug 11, 2010 at 8:05 PM

Hi Andrus,

I'll post a sample project in the next day or so.

If you add an outlookBar and name if Menu..

<outlook:OutlookBar x:Name="Menu" Width="200" />

You will be able to use code like this to create buttons...

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            LoadMenu();
        }

        private void LoadMenu()
        {

            OutlookBarButton homeOulookBarButton = new OutlookBarButton();
            OutlookBarButton contactsOulookBarButton = new OutlookBarButton();
            OutlookBarButton settingsOulookBarButton = new OutlookBarButton();

            BitmapImage homeBitmapImage = new BitmapImage(new Uri("Images/Home.png", UriKind.RelativeOrAbsolute));
            BitmapImage contactsBitmapImage = new BitmapImage(new Uri("Images/Persons.png", UriKind.RelativeOrAbsolute));
            BitmapImage settingsBitmapImage = new BitmapImage(new Uri("Images/Settings.png", UriKind.RelativeOrAbsolute));
            
            
            homeOulookBarButton.Header = "Home";
            contactsOulookBarButton.Header = "Contacts";
            settingsOulookBarButton.Header = "Settings";


            homeOulookBarButton.HeaderImage = homeBitmapImage;
            contactsOulookBarButton.HeaderImage = contactsBitmapImage;
            settingsOulookBarButton.HeaderImage = settingsBitmapImage;


            homeOulookBarButton.Content = "The is the Home content";
            contactsOulookBarButton.Content = "This is the Contacts content";
            settingsOulookBarButton.Content = "This is the Settings content";

            Menu.Items.Add(homeOulookBarButton);
            Menu.Items.Add(contactsOulookBarButton);
            Menu.Items.Add(settingsOulookBarButton);

            //This shouldn't be necessary but seems to be required. Need to review the API.
            Menu.IsExpanded = false;
            Menu.IsExpanded = true;

        }
    }

Thanks

Delordson

Aug 13, 2010 at 2:35 PM
Thank you.

Do you have sample how to add menu bars with image, text and right-aligned
shortcut key mnemonic as
outlook bar content, so that some button content with twno menu items looks
like

IMAGE1 Invoice Ctrl+Alt+E

IMAGE2 Order Ctrl+Alt+O

Should StackPanel used other idea ?

Andrus.
Coordinator
Aug 15, 2010 at 9:04 AM

Hi,

 

I've uploaded a sample project.

http://silverlightoutlook.codeplex.com/wikipage?title=Dynamic&referringTitle=Documentation

 

Thanks

Delordson