WPF:如何将Mahapps Metro应用程序重制为类库?

时间:2016-01-27 17:05:57

标签: wpf mahapps.metro

我有一个WPF Mahapps Metro风格的应用程序。 这是包含Usercontrol的MainWindow,里面它与其他Usercontrol一起工作,如向导页面。

现在我正在尝试将其重新制作成类库,以便在WiX Bootstraper应用程序中使用它。

问题之一是:在哪里放置资源

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

我已将它放到主Usercontrol xml中,但这是一个错误:

    <UserControl.Resources>
        <ResourceDictionary> <------------x:Key required?
            <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>

        <DataTemplate DataType="{x:Type viewModel:ViewModelAlreadyInstalledPage}">
            <view:AlreadyInstalledPage/>
        </DataTemplate>
...

1 个答案:

答案 0 :(得分:2)

您必须将DataTemplate放在ResourceDictionary

<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>

    <DataTemplate DataType="{x:Type viewModel:ViewModelAlreadyInstalledPage}">
        <view:AlreadyInstalledPage />
    </DataTemplate>
</ResourceDictionary>