我无法在Visual Studio中显示WPF Ribbon项目。这里是一个链接,针对在Visual Studio 2010中遇到问题的人的帖子。
我已经尝试了那里提出的所有建议,但都没有成功。
我安装了Visual Studio 2012 Express for Desktop,但什么也没显示出来。我已经尝试卸载和重新安装,但没有运气。
一个简单的解决方法是将<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) 运行程序!