WPF:如何将 Mahapps Metro 应用程序重新制作为 class 库?
WPF: How to remake Mahapps Metro application to class library?
我有一个 WPF Mahapps Metro 风格的应用程序。
这是包含 Usercontrol 的 MainWindow,在它内部与其他 Usercontrols 一起工作,例如 Wizard Pages。
现在我正在尝试将它重新制作成一个 class 库,以便在 WiX Bootstraper 应用程序中使用它。
问题之一是:
中的资源放在哪里
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
我已经把它放到了主用户控件中 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>
...
您必须将 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>
我有一个 WPF Mahapps Metro 风格的应用程序。 这是包含 Usercontrol 的 MainWindow,在它内部与其他 Usercontrols 一起工作,例如 Wizard Pages。
现在我正在尝试将它重新制作成一个 class 库,以便在 WiX Bootstraper 应用程序中使用它。
问题之一是:
中的资源放在哪里 <Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
...
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
我已经把它放到了主用户控件中 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>
...
您必须将 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>