构建类似Office 2007框架的WPF应用程序(1)

近一个月,学习了WPF相关知识。在这里,我利用构建一个类似Office 2007框架的WPF应用程序,来总结学习WPF的个人体验。

一、需求

利用WPF,构建一个程序,框架类似Office 2007.如图:



二、关于Ribbon

这里就不对Ribbon功能区做详细介绍,网上可以搜索相关资料。

只想说明,在VS2012及以前的版本,没有内置Ribbon控件。需要到微软的Download Center搜索“WPF Ribbon”,下载Microsoft Ribbon for WPF.msi文件来安装。

VS2015已经内置Ribbon控件,直接使用就好。

三、新建项目

我们使用微软提供的WPF应用程序模板,来创建新项目。

启动VS2015,执行File ->New -> Project,会弹出下列新项目窗口,接着,我们选择Templates -> Visual C# -> Windows -> WPF Application,最后修改项目名和存放目录(我这里就用默认),点击OK按钮,即生成一个WPF应用程序模板。


四、UI设计

我们先看MainWindow.xaml的最初代码,简单得很,就两个标签Window和Grid,如下:

<Window xmlns:my="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"  x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>

    </Grid>
</Window>

回顾我们的需求:一个Ribbon功能区,一个主窗口和一个状态栏。那UI布局就简单将Grid分三行一列就可以了。分别是:

1)        第一行放Ribbon控件。

2)        第二行放Frame控件。Frame控件作为嵌套Page和UserControl等窗体的顶级控件。

3)        第三行放StatusBar控件。

<Window xmlns:my="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"  x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <my:Ribbon Grid.Row="0">
            
        </my:Ribbon>
        <Frame Grid.Row="1">
            
        </Frame>

        <StatusBar Grid.Row="2">
            
        </StatusBar>

    </Grid>
</Window>
编译,运行,最简单的类似Office 2007的程序如下:

先写到这里,下一篇文章介绍Ribbon功能区和状态栏的处理。

-------------------

源码下载地址:http://download.csdn.net/detail/mandylover/9737118


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值