문제

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.

도움이 되었습니까?

해결책

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top