RibbonButtonコントロールを使用する

スポンサーリンク

Ribbonインターフェースで使用するボタンはRibbonButtonコントロールです。

ボタンにテキストを表示する場合はLabelプロパティを、イメージを表示する場合はSmallImageSourceプロパティ(小さいアイコン)またはLargeImageSourceプロパティ(大きいアイコン)を使用します。

またボタンが押されたことを知るにはClickイベントを使用します。

下記はRibbonButtonコントロールを使用する例です。

RibbonButtonコントロールを使用する例

XAMLの例

<ribbon:Ribbon x:Name="Ribbon">
    <ribbon:RibbonTab x:Name="HomeTab"
                      Header="Home">
        <ribbon:RibbonGroup x:Name="Group1"
                            Header="Group1">
            <ribbon:RibbonButton Label="新規作成" KeyTip="N"
                                 LargeImageSource="Images/NewDocument_32x32.png" 
                                 Name="RibbonButtonNew" />
            <ribbon:RibbonButton Label="保存" KeyTip="S"
                                 SmallImageSource="Images/saveHS.png" 
                                 Name="RibbonButtonSave" />
        </ribbon:RibbonGroup>
    </ribbon:RibbonTab>
</ribbon:Ribbon>

VBの例

' [新規作成]ボタンクリック時の処理
Private Sub RibbonButtonNew_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles RibbonButtonNew.Click
    Dim openDialog As New Microsoft.Win32.OpenFileDialog()
    openDialog.ShowDialog()
End Sub

' [保存]ボタンクリック時の処理
Private Sub RibbonButtonSave_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles RibbonButtonSave.Click
    Dim saveDialog As New Microsoft.Win32.SaveFileDialog()
    saveDialog.ShowDialog()
End Sub

C#の例

// [新規作成]ボタンクリック時の処理
private void RibbonButtonNew_Click(object sender, RoutedEventArgs e)
{
    Microsoft.Win32.OpenFileDialog openDialog = new Microsoft.Win32.OpenFileDialog();
    openDialog.ShowDialog();
}

// [保存]ボタンクリック時の処理
private void RibbonButtonSave_Click(object sender, RoutedEventArgs e)
{
    Microsoft.Win32.SaveFileDialog saveDialog = new Microsoft.Win32.SaveFileDialog();
    saveDialog.ShowDialog();
}
タイトルとURLをコピーしました