[英]Create Ribbon in WPF App with with Visual Studio 2017 on Windows 10
我已在Visual Studio 2017中为Windows 10上的Windows Classic Desktop创建了一个新的WPF应用程序。
我通过以下方式将功能区添加到新应用程序中。 xaml代码:
<r:RibbonWindow x:Class="AKnowledgeBase.MainWindow"
xmlns:r1="http://schemas.microsoft.com/winfx/2006/xaml/presentation/ribbon"
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:AKnowledgeBase"
mc:Ignorable="d"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
xmlns:r2="clr-namespace:Microsoft.Windows.Controls.Ribbon.Primitives;assembly=RibbonControlsLibrary"
Title="AKnowledgeBase" Height="350" Width="525">
<DockPanel>
<r:Ribbon>
<r2:RibbonTabsPanel></r2:RibbonTabsPanel>
</r:Ribbon>
</DockPanel>
</r:RibbonWindow>
并更改基类:
public partial class MainWindow : RibbonWindow
{
public MainWindow()
{
InitializeComponent();
}
}
但是结果应用程序窗口看起来很难看:
在上图中,您可以看到资源管理器标题(在Windows10中具有标准视图)和创建的应用程序标题(类似于Windows98样式的视图)。
为什么会发生以及如何解决?
UPD1 :
当我使用下面建议的对System.Windows.Controls.Ribbon.dll的引用时,主窗口的左侧和右侧都有蓝色的伪像:
另外,当我最大化此窗口时-出现带标题的错误:
文本被部分剪切。
添加对System.Windows.Controls.Ribbon.dll
的引用,然后尝试以下XAML标记:
<RibbonWindow x:Class="AKnowledgeBase.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:r2="clr-namespace:System.Windows.Controls.Ribbon.Primitives;assembly=System.Windows.Controls.Ribbon"
mc:Ignorable="d"
Title="Window14" Height="300" Width="300">
<Grid>
<DockPanel>
<Ribbon>
<r2:RibbonTabsPanel></r2:RibbonTabsPanel>
</Ribbon>
</DockPanel>
</Grid>
</RibbonWindow>
您可能不需要RibbonWindow
:
<Window x:Class="AKnowledgeBase.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:WpfApplication7"
xmlns:r2="clr-namespace:System.Windows.Controls.Ribbon.Primitives;assembly=System.Windows.Controls.Ribbon"
mc:Ignorable="d"
Title="Window14" Height="300" Width="300">
<Grid>
<DockPanel>
<Ribbon>
<r2:RibbonTabsPanel></r2:RibbonTabsPanel>
</Ribbon>
</DockPanel>
</Grid>
</Window>
您可能已经添加了一些基于主题的样式以及r,r1和r2参考。 我建议您寻找一种构建功能区而不覆盖默认样式的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.