在运行时xaml查看器中使用main方法和加载资源不工作
本文关键字:方法 main 加载 资源 工作 xaml 运行时 | 更新日期: 2023-09-27 18:14:29
我在我的项目中使用单个应用程序类,我想在我的应用程序中创建自定义主方法,但我有一个问题:我无法查看*。Xaml文件在我的项目(页面和用户控件在visual studio)我得到这个警告不样式和模板工作(因为我的资源文件正在加载运行时):在所有xaml文件中都有警告:资源"name"无法解析。
自定义app.cs文件代码:
public partial class App : Application, ISingleInstanceApp
{
private const string Unique = "Agrin Download Manager";
[STAThread]
public static void Main()
{
if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
{
var application = new App();
application.InitializeComponent();
application.Run();
// Allow single instance code to perform cleanup operations
SingleInstance<App>.Cleanup();
}
}
private bool _contentLoaded;
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public void InitializeComponent()
{
if (_contentLoaded)
{
return;
}
_contentLoaded = true;
this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
Assembly a = Assembly.GetExecutingAssembly();
using (Stream stream = a.GetManifestResourceStream("Agrin.Windows.UI.AppResources.xaml"))
{
XmlReader XmlRead = XmlReader.Create(stream);
Application.Current.Resources =
(ResourceDictionary)XamlReader.Load(XmlRead);
XmlRead.Close();
}
}
}
和我的appresource。xaml(从InitializeComponent方法加载运行时):
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Themes/ControlStyles.xaml"/>
<ResourceDictionary Source="Resources/Themes/VectorStyles.xaml"/>
<ResourceDictionary Source="Resources/Themes/Brushes.xaml"/>
<ResourceDictionary Source="Resources/Themes/LanguageAndFonts.xaml"/>
<ResourceDictionary Source="Resources/Themes/ColorsResource.xaml"/>
<ResourceDictionary Source="Resources/Themes/WpfDataGridTheme.xaml"/>
<!--<ResourceDictionary Source="Theme/PathToBitmapResources.xaml"/>-->
</ResourceDictionary.MergedDictionaries>
请帮助我在visual studio中使用xaml查看器,AppResources。
好的,我改变了我的项目AppResources。Xaml文件:
<Application
x:Class="Agrin.Windows.UI.App2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Converters.xaml"/>
<ResourceDictionary Source="Resources/Themes/ControlStyles.xaml"/>
<ResourceDictionary Source="Resources/Themes/VectorStyles.xaml"/>
<ResourceDictionary Source="Resources/Themes/Brushes.xaml"/>
<ResourceDictionary Source="Resources/Themes/LanguageAndFonts.xaml"/>
<ResourceDictionary Source="Resources/Themes/ColorsResource.xaml"/>
<ResourceDictionary Source="Resources/Themes/WpfDataGridTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>