Desperately Seeking Love of Sophie

Using Toolbar control

Posted in Professional, Software by Vivek on May 28th, 2007

Few people have asked me about posting a sample about how to use the toolbar sample. Here is what it looks like…

Here is what Page.xaml looks like…

<Canvas x:Name="rootCanvas"
        xmlns="http://schemas.microsoft.com/client/2007"
        xmlns :x ="http://schemas.microsoft.com/winfx/2006/xaml"
        Loaded="Page_Loaded"
        x:Class="ControlApplication.ControlUse;assembly=ClientBin/ControlApplication.dll"
        xmlns:Custom="clr-namespace:SPFControls;assembly=ClientBin/Toolbar.dll"
        Width="1000"
        Height="1000"
        Background="White">
  <TextBlock Canvas.Top="70"  Canvas.Left ="250" Name="txtValue" FontSize="20"/>
  <Custom:Toolbar Name="toolbar" Canvas.Top="200" Canvas.Left="100" Height="50" Width="500"/>
</Canvas>

Here is what Page.xaml.cs looks like

 

using System;
using System.Linq;
using System.Xml;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ControlApplication
{
    public partial class ControlUse : Canvas
    {

        TextBlock _textblock;
        SPFControls.Toolbar _toolbar;

        public void Page_Loaded(object o, EventArgs e)
        {
            InitializeComponent();
            Canvas canvas1 = o as Canvas;
            _textblock = canvas1.FindName("txtValue") as TextBlock;
            _toolbar = canvas1.FindName("toolbar") as SPFControls.Toolbar;

            for (int i = 0; i < 8; i++)
            {
                SPFControls.ToolbarButton tb = new SPFControls.ToolbarButton();
                string uri = "Images/image" + (i + 1).ToString() + ".jpg";
                tb.Image = new Uri(uri, UriKind.Relative);
                tb.ToolTip = uri;
                tb.Click += new EventHandler<EventArgs>(tb_Click);
                _toolbar.ToolBarCollection.Add(tb);
            }
        }

        void tb_Click(object sender, EventArgs e)
        {
            _textblock.Text = ((SPFControls.ToolbarButton)sender).Image.ToString();
        }
    }
}

Hope this helps!

Tagged with:

7 Responses to 'Using Toolbar control'

Subscribe to comments with RSS or TrackBack to 'Using Toolbar control'.

  1. [...] http://vivekdalvi.wordpress.com/2007/05/28/using-toolbar-control/ Posted: Monday, May 28, 2007 6:37 PM by vivekd Filed under: Silverlight [...]

  2. Mario said, on May 29th, 2007 at 12:57 am

    Whenever o try to run this sample i get the following message:
    ErrorCode: 2210
    ErrorType: ParseError
    Message: AG_E_INVALID_ARGUMENT
    XamlFile:Page.xaml
    Line:12
    Position: 93

    Can you help me?

  3. vivekdalvi said, on May 29th, 2007 at 1:23 am

    have you linked to Toolbar.dll (or it is project?) I have blogged about creating toolbar too. you need to have the control to use this here

  4. vivekdalvi said, on May 29th, 2007 at 1:29 am

    try this
    http://blogs.msdn.com/vivekd/attachment/2948692.ashx

  5. Colin said, on May 31st, 2007 at 8:12 am

    I met same problem when I create my own silverlight controls…

  6. Rajesh Kumar said, on October 23rd, 2007 at 4:54 am

    I have tried to run the control sample for toolbar bt when i run a get a blank page and sometimes the icon/link to download silverlight pls help me in this regard since i m new to this

  7. LOOI said, on November 14th, 2007 at 4:00 am

    I encounter this error message when called this
    SPFControls.ToolbarButton tb = new SPFControls.ToolbarButton();

    and error message:
    Catastrophic failure (Exception from HRESULT: 0×8000FFFF (E_UNEXPECTED))

    Any idea?

Leave a Reply