Smart Office SDK – First Project Part 8 – the Next, Previous, Close, the Toolbar and CommandBar – Gah!

Sometimes things don’t go according to plan, sometimes you fail to dig through enough information which will save you a lot of work…

In my previous post https://potatoit.wordpress.com/2013/09/19/smart-office-sdk-first-project-part-7-the-toolbar/ I talked about recreating the M3 toolbar with the select, create, display options etc on it. (I was close to producing an enhancement request asking for access to the object which creates the toolbar – but then the psychological damage incurred when using the XtremePortal made me reconsider. 🙂 )

Today I was looking for a way to get the little arrow you see next to the “Next” button or the cross on the close. I couldn’t find anything similar in the images. It turns out that I was looking in the wrong place. And to my surprise I discovered the Mango.DesignSystem namespace and the goodies it contains.

Namely the “ThemeIconButton” and it has a nice property called “IconName” which has the enumerable list “ThemeIconButtonName” in that enumeration there is the handy “Next”, “Previous”, and “Close” entries.

So by defining <ThemeIconButton Content=”Close” IconName=”Close” IsPrimary=”False” IconAlignment=”Left” /> I could have a standard styled Close button…yay!

…But…

…this prompted me to start poking at things in this namespace…

…and I discovered the “CommandBar”…(the control that houses the toolbar and has a little separator line)…

…and then I discovered…

…the IconButton…and it’s IconName property had enumerables such as “Create”, “Edit”, “Display”.

A quick dropping of them on to a panel and I discovered that the imaging swapping I manually created in my previous post happens automatically. Infact, the only real issue was that I needed to change the size of the IconButton.

So…I quickly ripped out almost all of my toolbar, cutting the code down to about 50% of what it was…I left some of the code in there for my sanity and to reduce the changes to the other parts of my project – I’ll call it my helper code, others will probably just call it being lazy.

Here is the updated code XAML and C# code behind my toolbar.

<UserControl x:Class="VesselMod.ISOStandardToolbar"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ds="clr-namespace:Mango.DesignSystem;assembly=DesignSystem"
             mc:Ignorable="d" 
             >
    <Grid>
        <StackPanel Name="spTools" Orientation="Horizontal">
            <ds:IconButton IconName="New" Width="30" Height="36" Name="btnCreate" Click="ToolbarButton_Click" ToolTip="Create" />
            <ds:IconButton IconName="Select" Width="30" Height="36" Name="btnSelect" Click="ToolbarButton_Click" ToolTip="Select" />
            <ds:IconButton IconName="Edit" Width="30" Height="36"  Name="btnChange" Click="ToolbarButton_Click" ToolTip="Change"/>
            <ds:IconButton IconName="Copy" Width="30" Height="36" Name="btnCopy"  Click="ToolbarButton_Click" ToolTip="Copy"/>
            <ds:IconButton IconName="Display" Width="30" Height="36" Name="btnDisplay"  Click="ToolbarButton_Click" ToolTip="Display"/>
            <ds:IconButton IconName="Delete" Width="30" Height="36" Name="btnDelete"  Click="ToolbarButton_Click" ToolTip="Delete"/>
            <ds:IconButton IconName="Refresh" Width="30" Height="36" Name="btnRefresh"  Click="ToolbarButton_Click" ToolTip="Refresh"/>
        </StackPanel>
    </Grid>
</UserControl>

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;

namespace VesselMod
{
    /// <summary>
    /// Interaction logic for ISOStandardToolbar.xaml
    /// </summary>
    public partial class ISOStandardToolbar : UserControl
    {
        public delegate void CreateClickedEventHandler(object sender, RoutedEventArgs e);
        public event CreateClickedEventHandler CreateClicked;
        public delegate void SelectClickedEventHandler(object sender, RoutedEventArgs e);
        public event SelectClickedEventHandler SelectClicked;
        public delegate void ChangeClickedEventHandler(object sender, RoutedEventArgs e);
        public event ChangeClickedEventHandler ChangeClicked;
        public delegate void CopyClickedEventHandler(object sender, RoutedEventArgs e);
        public event CopyClickedEventHandler CopyClicked;
        public delegate void DeleteClickedEventHandler(object sender, RoutedEventArgs e);
        public event DeleteClickedEventHandler DeleteClicked;
        public delegate void DisplayClickedEventHandler(object sender, RoutedEventArgs e);
        public event DisplayClickedEventHandler DisplayClicked;
        public delegate void RefreshClickedEventHandler(object sender, RoutedEventArgs e);
        public event RefreshClickedEventHandler RefreshClicked;

        public bool RefreshEnabled
        {
            get
            {
                return btnRefresh.IsEnabled;
            }
            set
            {
                btnRefresh.IsEnabled = value;
            }
        }

        public bool DisplayEnabled
        {
            get
            {
                return btnDisplay.IsEnabled;
            }
            set
            {
                btnDisplay.IsEnabled = value;
            }
        }

        public bool DeleteEnabled
        {
            get
            {
                return btnDelete.IsEnabled;
            }
            set
            {
                btnDelete.IsEnabled = value;
            }
        }

        public bool CopyEnabled
        {
            get
            {
                return btnCopy.IsEnabled;
            }
            set
            {
                btnCopy.IsEnabled = value;
            }
        }

        public bool ChangeEnabled
        {
            get
            {
                return btnChange.IsEnabled;
            }
            set
            {
                btnChange.IsEnabled = value;
            }
        }

        public bool SelectEnabled
        {
            get
            {
                return btnSelect.IsEnabled;
            }
            set
            {
                btnSelect.IsEnabled = value;
            }
        }

        public bool CreateEnabled
        {
            get
            {
                return btnCreate.IsEnabled;
            }
            set
            {
                btnCreate.IsEnabled = value;
            }
        }

        public ISOStandardToolbar()
        {
            InitializeComponent();

            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            spTools.Background = Mango.UI.Core.StyleManager.BrushBackgroundApplicationBar;
            spTools.Orientation = Orientation.Horizontal;

            btnSelect.IsEnabled = false;
            btnChange.IsEnabled = false;
            btnCopy.IsEnabled = false;
            btnDisplay.IsEnabled = false;
            btnDelete.IsEnabled = false;
            btnCreate.IsEnabled = true;
            btnRefresh.IsEnabled = true;
        }

        /// <summary>
        /// One of the buttons has been clicked, generate an event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ToolbarButton_Click(object sender, RoutedEventArgs e)
        {
            Button currentButton = sender as Button;

            if (currentButton != null)
            {
                if (true == currentButton.IsEnabled)
                {
                    switch (currentButton.Name)
                    {
                        case "btnCreate":
                            if (null != CreateClicked)
                            {
                                CreateClicked(sender, e);
                            }                            
                            break;
                        case "btnSelect":
                            if (null != SelectClicked)
                            {
                                SelectClicked(sender, e);
                            }
                            break;
                        case "btnChange":
                            if (null != ChangeClicked)
                            {
                                ChangeClicked(sender, e);
                            }                            
                            break;
                        case "btnCopy":
                            if (null != CopyClicked)
                            {
                                CopyClicked(sender, e);
                            }
                            break;
                        case "btnDelete":
                            if (null != DeleteClicked)
                            {
                                DeleteClicked(sender, e);
                            }
                            break;
                        case "btnDisplay":
                            if (null != DisplayClicked)
                            {
                                DisplayClicked(sender, e);
                            }
                            break;
                        case "btnRefresh":
                            if (null != RefreshClicked)
                            {
                                RefreshClicked(sender, e);
                            }
                            break;
                    }
                }
            }
        }
    }
}

This entry was posted in Development, M3 / MoveX, SDK. Bookmark the permalink.

4 Responses to Smart Office SDK – First Project Part 8 – the Next, Previous, Close, the Toolbar and CommandBar – Gah!

  1. Pingback: Hello World of Infor Smart Office SDK | M3 ideas

  2. Hello,
    I want to create a SDK program get gets as close to the look an feel of a real infor Program. When I try to work with
    xmlns:ds=”clr-namespace:Mango.DesignSystem;assembly=DesignSystem”
    mc:Ignorable=”d”
    to create my menu / Commandbar

    The Xaml editor Complains that , ds:CommandBarButton, … does not exist in namespace:Mango.DesignSystem;assembly=DesignSystem (Autocomple however is working just fine…) And i have an example where this code works.

    Do you have a workaround for this issue ? I use Visual studio 2017.

    • potatoit says:

      Does the code compile?

      When I have the XAML editor open in Visual Studio I tend to get errors, but it still compiles okay.

      Typically for my projects I declare:
      xmlns:ds=”clr-namespace:Mango.DesignSystem;assembly=DesignSystem”
      xmlns:Controls=”clr-namespace:Mango.UI.Controls;assembly=Mango.UI”

      And when I am doing the control placement I have this entry – which I comment out before I deploy otherwise you will get the blue skin for your controls regardless of what colours are set within Smart Office.

      Other issues with the XAML editor. Check the reference assemblies to make sure that they aren’t ‘blocked’. Right click the property of the .dll and select properties. There may be the unblock option.

      Hope that helps,

      Cheers,
      Scott

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s