代码之家  ›  专栏  ›  技术社区  ›  Drake

放置资源的位置

wpf
  •  0
  • Drake  · 技术社区  · 6 年前

    Style 在我的 App.xaml 在其他页面上使用。但是我想把我的项目编译成一个需要删除的.dll 应用程序xaml . 所以我需要把我的 风格 其他地方(最好是在一个全球性的地方,而不是在我做的每一页)。我可以把它放在哪里,怎么用?

    顺便说一下,我用的是MvvmCross,但我觉得这不相关。

    2 回复  |  直到 6 年前
        1
  •  1
  •   Igor Meszaros    6 年前

    基本上,您可以在任何您认为合适的地方创建一个包含 <ResourceDictionary> 然后您可以在任何需要的地方加载这些资源字典,如:

     <Page.Resources>
      <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
          <ResourceDictionary Source="myresourcedictionary.xaml"/>
          <ResourceDictionary Source="myresourcedictionary2.xaml"/>
        </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
    </Page.Resources>
    

    更多细节 here

        2
  •  0
  •   RezaNoei    6 年前

    对于全局声明,如果您看到为App.Xaml生成的cs文件,您将看到类似于windowsForm的Program.cs文件(与表单部分类代码混合)。

    以下是此文件的一部分:(App.i.g.cs)

        public void InitializeComponent() {
            if (_contentLoaded) {
                return;
            }
            _contentLoaded = true;
    
            #line 7 "..\..\App.xaml"
            this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
    
            #line default
            #line hidden
            System.Uri resourceLocater = new System.Uri("/WpfPlayground;component/app.xaml", System.UriKind.Relative);
    
            #line 1 "..\..\App.xaml"
            System.Windows.Application.LoadComponent(this, resourceLocater);
    
            #line default
            #line hidden
        }
    

            System.Windows.Application.LoadComponent(this, resourceLocater);
    

    如果您创建的文件符合App.xaml文件(您知道这是EXE文件的主要入口点),则无需依赖此文件。

    注: