Quick toolbar for WPF4Ribbon Development (QuickAccessToolbar)

Source: Internet
Author: User
Microsoft introduced a new concept "Ribbon toolbar" in Office2007 and Windows7. The interface design mode of the Ribbon toolbar allows you to quickly and conveniently find the required tools, in addition, this intuitive design helps users discover other features of the software to better understand the features of the application. Design Ribbon

Microsoft introduced a new concept in Office 2007 and Windows 7: "Ribbon toolbar". The interface design mode of the Ribbon toolbar allows you to quickly and conveniently find the required tools, in addition, this intuitive design helps users discover other features of the software to better understand the features of the application. Design Ribbon

Microsoft introduced a new concept in Office 2007 and Windows 7: "Ribbon toolbar". The interface design mode of the Ribbon toolbar allows you to quickly and conveniently find the required tools, in addition, this intuitive design helps users discover other features of the software to better understand the features of the application.

The purpose of Ribbon design is to replace the old-fashioned toolbar to make the use of applications more convenient. Of course, Microsoft also provides developers with the Ribbon Toolbar Control Library (WPF Ribbon Control), so that you can develop applications with a toolbar similar to Office 2007 Ribbon.

Get Office UI authorization

Before Ribbon development, you must first obtain the Office UI authorization and download the Ribbon control library (DLL ). Go to the authorization page and click "License the Office UI ".

Log on to Windows Live ID and enter your personal information. On the download page, obtain "WPF Ribbon Control" (Note: This program is only the CTP version currently ). You can also download other related materials.

Ribbon interface structure

After downloading the Ribbon control library, you can use the Ribbon toolbar in the program. Before formal development, let's take a look at the basic structure of the Ribbon toolbar. Is the Office 2007 Ribbon toolbar, which is mainly dividedTab(Home, Insert, etc ),Group(Clipboard, Font, Paragraph, etc ),Application Button,Quick Access Toolbar. This article describes the development of the Quick Access Toolbar.

Quick toolbar Development

 
      ... ...
 

Next, add three buttons in the shortcut toolbar to implement the following functions: "Save Document", "clear document", and "help ". In fact, Ribbon itself is a Command toolbar. We can Define the corresponding Content.

In the following code, CanExecute is used to determine whether to execute Command, and Executed is used to execute Command-related events. SmallImageSource and LargeImageSource are used to set the toolbar size icons, so that the window size changes accordingly.

     
      
      
  
 
     
          
               
                    
                     
                     
                 
            
   
   

In the above program, RibbonQuickAccessToolBar. Placement is used to set whether the shortcut toolbar allows custom adjustments. As shown in, you can remove the Help button from the shortcut toolbar. If this value is not set, it cannot be adjusted by default, that is, the key content in the toolbar is fixed.

Finally, add the C # Code Completion event content for all RibbonCommand events. In the document save dialog box, you can use the CommonSaveFileDialog class of Windows API Code Pack to save the document.

private void SaveCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e){    e.CanExecute = true;}private void SaveCommand_Executed(object sender, ExecutedRoutedEventArgs e){    ShellContainer sc = KnownFolders.DocumentsLibrary as ShellContainer;    CommonSaveFileDialog csfd = new CommonSaveFileDialog();    csfd.InitialDirectoryShellContainer = sc;    csfd.DefaultExtension = ".txt";    csfd.Filters.Add(new CommonFileDialogFilter("Text Files", "*.txt"));    if (csfd.ShowDialog() == CommonFileDialogResult.OK)    {        File.WriteAllText(csfd.FileName, txtBox.Text);    }}private void ClearCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e){    e.CanExecute = true;}private void ClearCommand_Executed(object sender, ExecutedRoutedEventArgs e){    txtBox.Text = null;}private void HelpCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e){    e.CanExecute = true;}private void HelpCommand_Executed(object sender, ExecutedRoutedEventArgs e){    MessageBox.Show("You have clicked the help button.");}

Run:

Now, the development content of the shortcut toolbar is described here. The next article describes how to develop the Application Menu, that is, the content in the notepad icon in the upper left corner. Stay tuned... ...

Related Materials

1. Office UI Licensing Developer Center
Http://msdn.microsoft.com/en-us/office/aa973809.aspx

2. Ribbons
Http://msdn.microsoft.com/en-us/library/cc872782.aspx

3. WPF Ribbon Preview
Http://www.codeplex.com/wikipage? ProjectName = wpf & title = WPF % 20 Ribbon % 20 Preview

4. WPF 4 (VS 2010 and. NET 4.0 Series)
Http://weblogs.asp.net/scottgu/archive/2009/10/26/wpf-4-vs-2010-and-net-4-0-series.aspx

5. Ribbon Feature Walkthrough
Http://windowsclient.net/wpf/wpf35/wpf-35sp1-ribbon-walkthrough.aspx? PageIndex = 1

6. Introducing the Windows Ribbon Framework
The http://msdn.microsoft.com/en-us/library/dd316910 (VS.85). aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.