2012年11月1日 星期四

在WPF設計Ribbon

本文使用工具 Visual Studio 2012 + .NET Framework 4.5

WPF現在可以設計類似 Office 2010 Ribbon效果的工具列了!!

建一個WPF APP

image

Add Reference:

image

修改MainWindow.xaml.cs,讓MainWindow 繼承自RibbonWindow

public partial class MainWindow : RibbonWindow
{
  public MainWindow()
  {
    InitializeComponent();
  }
}

修改MainWindow.xaml,將Window改RibbonWindow

image


加上<Ribbon></Ribbon>:

image

 

加圖檔到專案:

image

修改Ribbon:

<RibbonWindow x:Class="WpfApplication1.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>
        <Ribbon>
            <RibbonTab Header="檔案">
                <RibbonGroup >
                    <RibbonButton  Label="存檔" LargeImageSource="button.png" ></RibbonButton>
                    <RibbonButton Label="開檔" LargeImageSource="arrow left.png"></RibbonButton>
                </RibbonGroup>
            </RibbonTab>
            <RibbonTab Header="編輯">
                <RibbonGroup>
                    <RibbonButton  Label="複製" ></RibbonButton>
                    <RibbonButton  Label="貼上"></RibbonButton>
                </RibbonGroup>
            </RibbonTab>
        </Ribbon>
    </Grid>
</RibbonWindow>

按F5執行:

image

image

沒有留言:

總瀏覽量