没有“WPF Ribbon Application”的项目模板

7

我无法在Visual Studio中显示WPF Ribbon项目。这里是一个链接,针对在Visual Studio 2010中遇到问题的人的帖子。

我已经尝试了那里提出的所有建议,但都没有成功。

我安装了Visual Studio 2012 Express for Desktop,但什么也没显示出来。我已经尝试卸载和重新安装,但没有运气。

1个回答

15

一个简单的解决方法是将<Window>替换为<RibbonWindow>,并将<Ribbon>作为第一个子元素。请记住,Ribbon控件已经集成到.NET 4.5中。

首先编辑你的MainWindow.xaml,将Window替换为RibbonWindow,并添加<Ribbon x:Name="Ribbon" Title="Ribbon Title">

示例:

<RibbonWindow x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="MainWindow"
        x:Name="RibbonWindow"
        Width="640" Height="480">

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Ribbon x:Name="Ribbon" Title="Ribbon Title">
            ...........
        </Ribbon>
    </Grid>
</RibbonWindow>

您还需要编辑 MainWindow.xaml.cs,将其继承 RibbonWindow 类,而不是 Window

public partial class MainWindow : RibbonWindow

最后记得从.NET框架中导入参考。

System.Windows.Controls.Ribbon

编辑: 更新包含对VB.Net的解决方案。

1) 添加引用

  • 右键单击您的项目,选择添加引用
  • 在程序集和框架下找到System.Windows.Controls.Ribbon
  • 单击确定以保存。

2) 编辑您的MainWindow.xaml

  • 备份任何现有代码。
  • 使用我的示例中的代码替换默认模板。
  • <Ribbon></Ribbon>标签内添加新内容。

3) 编辑您的MainWindow.xaml.vb

  • 右键单击MainWindow.xaml并单击查看代码
  • Class Window更改为Class RibbonWindow

4) 运行程序!


为了让它更清晰,你只需在你的新项目中编辑我帖子中提到的现有文件。 - eandersson
再次感谢。顺便说一下,我正在使用VB。它无法识别RibbonWindow。但这可能是因为我不知道如何处理System.Windows.Controls.Ribbon或如何在VB中继承。 - James Satori-Brunet
我的错。它应该是几乎相同的。我会看看能否更新我的答案。 - eandersson
这完全不是你的错。你非常有帮助。 - James Satori-Brunet
当我使用RibboWindow时,功能区覆盖了标题栏。我使用了您的XAML代码片段,解决了这个问题。我不知道为什么,我没有注意到任何合理的原因。 - Saša Ćetković
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接