WPF窗口边框在使用Ribbon控件时出现异常

4
我正在使用WPF中的Ribbon控件,我注意到有两个不同的版本。
  1. 使用Microsoft.Windows.Controls.Ribbon;

    • 如果我在我的xaml和类中使用它,我的整个窗口将呈现出非常老旧的Windows样式。
  2. 使用System.Windows.Controls.Ribbon;

    • 如果我在我的xaml和类中使用它,我的Ribbontabs会突然无法正确填充。

当我同时使用它们时,会出现以下情况:

<ribbon:RibbonWindow x:Class="WPSDashboard.Views.ShellWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"
        xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary" 
        xmlns:prism="clr-namespace:Microsoft.Practices.Prism.Regions;assembly=Microsoft.Practices.Prism" 
        Title="WPSDashboard"
        x:Name="RibbonWindow"
        Width="640" Height="480">


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

        <!-- Ribbon Region -->
        <r:Ribbon x:Name="Ribbon" prism:RegionManager.RegionName="RibbonRegion">
            <r:Ribbon.ApplicationMenu>
                <r:RibbonApplicationMenu SmallImageSource="Images\SmallIcon.png">
                    <r:RibbonApplicationMenuItem Header="Exit"
                                                      x:Name="MenuItemExit"
                                                      ImageSource="Images\Exit.png"
                                                      Command="{Binding ExitCommand}"/>
                    </r:RibbonApplicationMenu>
            </r:Ribbon.ApplicationMenu>
        </r:Ribbon>

        <Grid x:Name="ClientArea" Grid.Row="1">                   

            <!-- Workspace Region-->
            <GridSplitter HorizontalAlignment="Left" Width="2" Grid.Column="1"/>
            <ContentControl x:Name="WorkspaceRegion" Grid.Column="1" prism:RegionManager.RegionName="WorkspaceRegion" />
        </Grid>

    </Grid>
    </ribbon:RibbonWindow>

我的Ribbontabs已经加载,但窗口现在看起来像这样: 我无法点击关闭、最小化和最大化。 <--- 截图 如何使边框恢复正常大小呢? 我不能用这种方式关闭我的窗口。
2个回答

5
我找到了让它看起来和运行得很好的最佳方式!

不要在xaml开头使用<ribbon:RibbonWindow标签,而是使用<Window标签。
还需要添加以下部分:

xmlns:r="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"

如果你的类中有: RibbonWindow,请将其删除。

如果上述方法不起作用,并且你不需要快速访问工具栏,则可以尝试以下操作: 返回到你的XAML,在Ribbon边距处更改为-22:

 <r:Ribbon x:Name="Ribbon" prism:RegionManager.RegionName="RibbonRegion" Margin="0,-22,0,0" >

现在我的应用程序看起来像这样(带有-22的边距): 查看图像描述 现在它看起来像一个普通的应用程序,没有丑陋的Windows 98或2000风格,关闭按钮、最小化按钮和最大化按钮都回来了!

2
这破坏了功能区窗口的快速链接。这不是一个完整的解决方案。 - j riv
我不知道这个问题是如何解决的,但我看到了你的评论并回到了这个旧项目。我注意到我不必使用-22的边距也能使其正常工作。我会编辑我的答案。 - MCollard
如果您再尝试一下这个解决方案就太好了。我编辑了答案。如果在您的情况下这不起作用,那肯定有其他问题。这只是我的问题的一个解决方案。 - MCollard

1
我个人会玩边际,或者更好的方法是调查那个带子的样式,并将其更改以满足我的需要。

感谢您关注我的问题,但问题是我无法点击关闭按钮、最大化按钮和最小化按钮。 - MCollard
是的,我能看到,尝试通过使用Visual Studio的Expression Blend更改Ribbon对象的样式来调整Ribbon的高度或边距。 - AymenDaoudi
由于使用了using System.Windows.Controls.Ribbon;库,某些原因导致控件的行为不同。 感谢您的回答!我改变了顶部边距,现在它适合了。 我感到很愚蠢之前没有找到这个。 :D - MCollard

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