0

How do you get a RibbonButton to open a Form (let's say Form1)? There is a click callback on RibbonButton called "Click" but I am not sure what to do with this. I am guessing something needs to go in the VB window but I have no idea what.

The MSDN library suggests "Event Click As RibbonControlEventHandler" which is great but what do you do with it?

Any help would be appreciated.

James Satori-Brunet
  • 901
  • 2
  • 13
  • 28
  • Well, you put the code that shows in the form in the event handler. I don't understand your problem. Is it that you don't know how to show a form? – Roger Rowland Mar 24 '13 at 11:30
  • Thanks for the reply. I need an answer that involves some code for the XAML which begins – James Satori-Brunet Mar 24 '13 at 11:41
  • Google finds more detail - e.g. http://vb2010wpf.blogspot.co.uk/ for VS2010 or http://www.c-sharpcorner.com/UploadFile/0b73e1/ribbon-control-in-wpf-4-5/ for VS2012 – Roger Rowland Mar 24 '13 at 11:52
  • Yes, I just tried it and you're right - it sucks - not at all intuitive. If I can figure it out, I'll post again .... – Roger Rowland Mar 24 '13 at 17:12

1 Answers1

0

Ok, I just got a simple version working. It turned out that by default the button is only 4x4 pixels and you can't see it to click it - not sure if that was your problem too. Anyway, this is what I did ...

I had a main window with the Ribbon and RibbonButton - sized and coloured so I could see it

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Ribbon x:Name="RibbonWin"  SelectedIndex="0">
            <RibbonButton x:Name="btnOne" Height="32" Width="32">
                <RibbonButton.Background>
                    <SolidColorBrush Color="Red"/>
                </RibbonButton.Background>
            </RibbonButton>
        </Ribbon>
    </Grid>
</Window>

Then I added a second Window to be shown on the click event

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
    </Grid>
</Window>

Finally, I added a Click handler for the RibbonButton on the main window

Private Sub btnOne_Click(sender As Object, e As RoutedEventArgs) Handles btnOne.Click
    Dim wnd As Window1 = New Window1
    wnd.ShowDialog()
End Sub

Now everything works as expected. Does that help?

Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
  • You are a gentleman and a scholar. This worked perfectly. Your time is much appreciated. I have scoured forums and websites trying to find this simple code and I haven't been able to do so, until now. – James Satori-Brunet Mar 24 '13 at 21:28