簡體   English   中英

在Windows 10上使用Visual Studio 2017在WPF應用中創建功能區

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM