'宣言 Public ReadOnly Property HasRecentItemsHeader As Boolean
public bool HasRecentItemsHeader {get;}
Private xamApplicationMenu As ApplicationMenu Private xamRibbon As XamRibbon Private Sub initRibbonItems() 'Create RibbonWindowContentHost Dim xamContentHost As New RibbonWindowContentHost() Me.Content = xamContentHost 'Create XamRibbon object xamRibbon = New XamRibbon() xamContentHost.Ribbon = xamRibbon DockPanel.SetDock(xamRibbon, Dock.Top) 'Create Application Menu xamApplicationMenu = New ApplicationMenu() xamRibbon.ApplicationMenu = xamApplicationMenu 'Create Image for Application Menu Dim bmpImage As New BitmapImage() bmpImage.BeginInit() bmpImage.UriSource = New Uri("/images/icons/Ribbon/xamRibbonDefaultApplicationIcon.png", UriKind.RelativeOrAbsolute) bmpImage.EndInit() xamApplicationMenu.Image = bmpImage addApplicationMenuItems() 'RecentItemsHeader Dim stackPanel As New StackPanel() xamApplicationMenu.RecentItemsHeader = stackPanel 'RecentItemsHeaderTemplate Dim dt As DataTemplate = DirectCast(FindResource("myDataTemplate"), DataTemplate) xamApplicationMenu.RecentItemsHeaderTemplate = dt 'RecentItems xamApplicationMenu.RecentItems.Add("1. Document1.doc") xamApplicationMenu.RecentItems.Add("2. Document2.doc") 'FooterToolbar Dim footerToolbar As New ApplicationMenuFooterToolbar() footerToolbar.Items.Add("Footer") Dim sepTool As New SeparatorTool() footerToolbar.Items.Add(sepTool) Dim btnExit As ButtonTool = getButtonTool("Exit", "btnExit", "") footerToolbar.Items.Add(btnExit) footerToolbar.HorizontalAlignment = HorizontalAlignment.Center xamApplicationMenu.FooterToolbar = footerToolbar End Sub Private Sub addApplicationMenuItems() 'Create ButtonTool with Caption "Remove" Dim btnToolRemove As ButtonTool = getButtonTool("Remove", "btnRemove", "/images/icons/Ribbon/New_Large.png") 'add event handler AddHandler btnToolRemove.Click, AddressOf btnToolRemove_Click xamApplicationMenu.Items.Add(btnToolRemove) 'Create ButtonTool with Caption "Clear" Dim btnToolClear As ButtonTool = getButtonTool("Clear", "btnClear", "/images/icons/Ribbon/EditUndo.png") 'add event handler AddHandler btnToolClear.Click, AddressOf btnToolClear_Click xamApplicationMenu.Items.Add(btnToolClear) 'Create MenuTool with Caption "Theme" Dim mnuToolTheme As New MenuTool() mnuToolTheme.LargeImage = getImageSource("/images/icons/Ribbon/Theme_Large.png") mnuToolTheme.Caption = "Theme" 'Add LabelTool Dim lblTool As New LabelTool() lblTool.Caption = "Change the visual theme of the application." mnuToolTheme.Items.Add(lblTool) 'Add RadioButtonTool Dim rbtThemeBlue As RadioButtonTool = getRadioButtonTool("Blue", "Office2k7Blue", "/images/icons/Ribbon/Theme_Blue.png") MenuToolBase.SetMenuItemDescription(rbtThemeBlue, "Use an Office2007 Blue theme.") mnuToolTheme.Items.Add(rbtThemeBlue) Dim btnHasRecentItemsHeader As ButtonTool = getButtonTool("HasRecentItemsHeader", "HasRecentItemsHeader", "") MenuToolBase.SetMenuItemDescription(btnHasRecentItemsHeader, "Has Recent Items Header.") AddHandler btnHasRecentItemsHeader.Click, AddressOf btnHasRecentItemsHeader_Click mnuToolTheme.Items.Add(btnHasRecentItemsHeader) xamApplicationMenu.Items.Add(mnuToolTheme) End Sub 'Get Image Source Private Function getImageSource(ByVal uriString As String) As BitmapImage Dim bmpImage As New BitmapImage() bmpImage.BeginInit() bmpImage.UriSource = New Uri(uriString, UriKind.RelativeOrAbsolute) bmpImage.EndInit() Return bmpImage End Function Private Function getButtonTool(ByVal caption As String, ByVal tagString As String, ByVal imageUriString As String) As ButtonTool Dim btnTool As New ButtonTool() btnTool.Caption = caption btnTool.Tag = tagString btnTool.LargeImage = getImageSource(imageUriString) Return btnTool End Function Private Function getRadioButtonTool(ByVal caption As String, ByVal tagString As String, ByVal imageUriString As String) As RadioButtonTool Dim rbtTool As New RadioButtonTool() rbtTool.Caption = caption rbtTool.Tag = tagString rbtTool.LargeImage = getImageSource(imageUriString) Return rbtTool End Function
private ApplicationMenu xamApplicationMenu; private XamRibbon xamRibbon; private void initRibbonItems() { //Create RibbonWindowContentHost RibbonWindowContentHost xamContentHost = new RibbonWindowContentHost(); this.Content = xamContentHost; //Create XamRibbon object xamRibbon = new XamRibbon(); xamContentHost.Ribbon = xamRibbon; DockPanel.SetDock(xamRibbon, Dock.Top); //Create Application Menu xamApplicationMenu = new ApplicationMenu(); xamRibbon.ApplicationMenu = xamApplicationMenu; //Create Image for Application Menu BitmapImage bmpImage = new BitmapImage(); bmpImage.BeginInit(); bmpImage.UriSource = new Uri("/images/icons/Ribbon/xamRibbonDefaultApplicationIcon.png", UriKind.RelativeOrAbsolute); bmpImage.EndInit(); xamApplicationMenu.Image = bmpImage; addApplicationMenuItems(); //RecentItemsHeader StackPanel stackPanel = new StackPanel(); xamApplicationMenu.RecentItemsHeader = stackPanel; //RecentItemsHeaderTemplate DataTemplate dt = (DataTemplate)FindResource("myDataTemplate"); xamApplicationMenu.RecentItemsHeaderTemplate = dt; //RecentItems xamApplicationMenu.RecentItems.Add("1. Document1.doc"); xamApplicationMenu.RecentItems.Add("2. Document2.doc"); //FooterToolbar ApplicationMenuFooterToolbar footerToolbar = new ApplicationMenuFooterToolbar(); footerToolbar.Items.Add("Footer"); SeparatorTool sepTool = new SeparatorTool(); footerToolbar.Items.Add(sepTool); ButtonTool btnExit = getButtonTool("Exit", "btnExit", ""); footerToolbar.Items.Add(btnExit); footerToolbar.HorizontalAlignment = HorizontalAlignment.Center; xamApplicationMenu.FooterToolbar = footerToolbar; } private void addApplicationMenuItems() { //Create ButtonTool with Caption "Remove" ButtonTool btnToolRemove = getButtonTool("Remove", "btnRemove", "/images/icons/Ribbon/New_Large.png"); //add event handler btnToolRemove.Click += new RoutedEventHandler(btnToolRemove_Click); xamApplicationMenu.Items.Add(btnToolRemove); //Create ButtonTool with Caption "Clear" ButtonTool btnToolClear = getButtonTool("Clear", "btnClear", "/images/icons/Ribbon/EditUndo.png"); //add event handler btnToolClear.Click += new RoutedEventHandler(btnToolClear_Click); xamApplicationMenu.Items.Add(btnToolClear); //Create MenuTool with Caption "Theme" MenuTool mnuToolTheme = new MenuTool(); mnuToolTheme.LargeImage = getImageSource("/images/icons/Ribbon/Theme_Large.png"); mnuToolTheme.Caption = "Theme"; //Add LabelTool LabelTool lblTool = new LabelTool(); lblTool.Caption = "Change the visual theme of the application."; mnuToolTheme.Items.Add(lblTool); //Add RadioButtonTool RadioButtonTool rbtThemeBlue = getRadioButtonTool("Blue", "Office2k7Blue", "/images/icons/Ribbon/Theme_Blue.png"); MenuToolBase.SetMenuItemDescription(rbtThemeBlue, "Use an Office2007 Blue theme."); mnuToolTheme.Items.Add(rbtThemeBlue); ButtonTool btnHasRecentItemsHeader = getButtonTool("HasRecentItemsHeader", "HasRecentItemsHeader", ""); MenuToolBase.SetMenuItemDescription(btnHasRecentItemsHeader, "Has Recent Items Header."); btnHasRecentItemsHeader.Click +=new RoutedEventHandler(btnHasRecentItemsHeader_Click); mnuToolTheme.Items.Add(btnHasRecentItemsHeader); xamApplicationMenu.Items.Add(mnuToolTheme); } //Get Image Source private BitmapImage getImageSource(string uriString) { BitmapImage bmpImage = new BitmapImage(); bmpImage.BeginInit(); bmpImage.UriSource = new Uri(uriString, UriKind.RelativeOrAbsolute); bmpImage.EndInit(); return bmpImage; } private ButtonTool getButtonTool(string caption, string tagString, string imageUriString) { ButtonTool btnTool = new ButtonTool(); btnTool.Caption = caption; btnTool.Tag = tagString; btnTool.LargeImage = getImageSource(imageUriString); return btnTool; } private RadioButtonTool getRadioButtonTool(string caption, string tagString, string imageUriString) { RadioButtonTool rbtTool = new RadioButtonTool(); rbtTool.Caption = caption; rbtTool.Tag = tagString; rbtTool.LargeImage = getImageSource(imageUriString); return rbtTool; }