【问题标题】:Mahapps Metro IssueMahapps地铁问题
【发布时间】:2016-04-12 20:10:16
【问题描述】:

背景

我第一次尝试使用 Mahapps Metro 在 WPF 中构建应用程序。我已按照 Mahapps 快速入门指南 here 中的所有步骤进行操作,但我的结果看起来完全不同(如下所示):

我不确定我还应该尝试什么。我的 XAML 文件与示例完全相同。

这是我的 App.xaml 文件的样子:

<Application x:Class="RxExample.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:RxExample"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            <!-- Accent and AppTheme setting -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

这是我的 MainWindow.xaml 文件的样子:

<Window x:Class="RxExample.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:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:RxExample"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="368*"/>
        <ColumnDefinition Width="149*"/>
    </Grid.ColumnDefinitions>

</Grid>

问题

这可能是什么问题,或者是 Mahapps?

【问题讨论】:

  • 你能告诉我们你的 MainWindow.xaml 吗?
  • @Pikoh 绝对。
  • 好的,尝试将您的&lt;Window x:Class... 更改为&lt;Controls:MetroWindow x:Class..
  • @Pikoh 现在我得到一个编译错误。 'MainWindow' 的部分声明不得指定不同的基类。
  • 当然,我忘了警告你。您还必须在 MainWindow.xaml.cs 中更改它,而不是 MainWindow : Window 它必须是 MainWindow : MetroWindow 他们必须匹配

标签: wpf xaml user-interface user-experience mahapps.metro


【解决方案1】:

尝试将以下内容添加到您的 App.xaml 文件中:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

还要确保在 MainWindow.xaml 中进行更改:

Window x:Class... for <Controls:MetroWindow x:Class..` 

MainWindow.xaml.cs 中更改基类,而不是MainWindow : Window,它必须是MainWindow : MetroWindow

【讨论】:

  • 这正是他们在快速入门中告诉您要做的事情。我已经做到了。
  • @StevieV 但是您问题中的代码显示您从Window 派生MainWindow 而不是MetroWindow
  • @ThomasFreudenberg 是的,这是非常错误的。其中一位用户让我解决了这个问题,它要么在 cmets 中,要么在这个答案中......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多