Question

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.

Était-ce utile?

La solution

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?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top