Results 1 to 6 of 6

Thread: [RESOLVED] Build toolbar buttons at runtime with tooltips

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Resolved [RESOLVED] Build toolbar buttons at runtime with tooltips

    I was using the "commented" out code below to create BUTTONS on a TOOLBAR at runtime - worked nicely.

    Code:
                    //List<String> list = new List<string>();
                    //list.Clear();
                    //for (int i = 0; i < x.Suggestions2.Count; i++)
                    //{
                    //    list.Add(x.Suggestions2[i]);
                    //}
                    //ToolList.ItemsSource = list;
    So I am now trying to build these buttons with tooltips as well - but when I run the code below it shows no buttons at all.

    Code:
                    
                    ToolBar tb = new ToolBar();
                    tb.Items.Clear();
                    for (int i = 0; i < x.Suggestions2.Count; i++)
                    {
                        Button ib = new Button();
                        ib.Content = x.Suggestions2[i];
                        ib.ToolTip = "tool tip " + x.Suggestions2[i];
                        tb.Items.Add(ib);
                    }
                    ToolList.ItemsSource = tb.ItemsSource;
                    //ToolList = tb;  <------- I tried this first - it also did not work
    Last edited by szlamany; Jul 28th, 2013 at 06:19 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Build toolbar buttons at runtime with tooltips

    nvm - I had to do this

    Code:
                    List<Button> list = new List<Button>();
                    list.Clear();
                    for (int i = 0; i < x.Suggestions2.Count; i++)
                    {
                        Button ib = new Button();
                        ib.Content = x.Suggestions2[i];
                        ib.ToolTip = "tool tip " + x.Suggestions2[i];
                        list.Add(ib);
                    }
                    ToolList.ItemsSource = list;
    The BINDING in WPF is really, really cool

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Build toolbar buttons at runtime with tooltips

    Argh - this is no longer resolved

    The code I used originally nicely took from a XAML item template

    Code:
                <ToolBar Grid.Row="1" Grid.ColumnSpan="2" Band="1" BandIndex="1" x:Name="ToolList">
                    <ToolBar.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Button Margin="2" Content="{Binding}" BorderBrush="{x:Null}" Click="Button_Click">
                                    <Button.Background>
                                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                            <GradientStop Color="#FFF3F3F3" Offset="0"/>
                                            <GradientStop Color="#FFEBEBEB" Offset="0.5"/>
                                            <GradientStop Color="#FFDDDDDD" Offset="0.5"/>
                                            <GradientStop Color="#FFFCF9FC" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Button.Background>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </ToolBar.ItemTemplate>
                </ToolBar>
    So the buttons had some styling. Creating the BUTTONS with the new code doesn't have the template styling.

    How would I create buttons with tooltips programmatically??

    Or how would I get some styling to copy from that template item while also creating these buttons?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Build toolbar buttons at runtime with tooltips

    I don't have VS here so perhaps you can try out if this will work?

    If you already have the template perhaps you can also try this out.
    Last edited by dee-u; Jul 29th, 2013 at 01:27 AM.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Build toolbar buttons at runtime with tooltips

    Thanks - both of those links have good info. I'm off for a few days of vacation (that's rare for me!)...

    The ParseXaml - have you used that a lot? Is it slow when building "lots" of controls at runtime?

    ParseXaml reminds me of how jQuery allows you to easily build new DOM/HTML stuff at runtime in a browser - very cool!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Build toolbar buttons at runtime with tooltips

    Ok - this became the XAML resource definition. Although I have to say that there seems to be very many ways to define resources...

    Code:
        <Window.Resources>
            <LinearGradientBrush x:Key="ButtonBrush" EndPoint="0,1" StartPoint="0,0">
                <GradientStop Color="#FFF3F3F3" Offset="0"/>
                <GradientStop Color="#FFEBEBEB" Offset="0.5"/>
                <GradientStop Color="#FFDDDDDD" Offset="0.5"/>
                <GradientStop Color="#FFFCF9FC" Offset="1"/>
            </LinearGradientBrush>
            <Style x:Key="ButtonStyle">
                <Setter Property="Control.Margin" Value="2"></Setter>
                <Setter Property="Control.BorderBrush" Value="{x:Null}"></Setter>
                <EventSetter Event="Button.Click" Handler="Button_Click" />
            </Style>
        </Window.Resources>
    and in code I used it like this

    Code:
                    List<Button> list = new List<Button>();
                    list.Clear();
                    for (int i = 0; i < x.Suggestions2.Count; i++)
                    {
                        Button ib = new Button();
                        ib.Style = (Style)FindResource("ButtonStyle");
                        ib.Background = (Brush)FindResource("ButtonBrush");
    .
    .
    .
    Seems to be working as expected now - thanks again (apparently I cannot rep you till I spread some around)

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width