相关疑难解决方法(0)

ResourceDictionary在一个单独的程序集中

我有资源字典文件(MenuTemplate.xaml,ButtonTemplate.xaml等),我想在多个单独的应用程序中使用.我可以将它们添加到应用程序的程序集中,但如果我在一个程序集中编译这些资源并让我的应用程序引用它,那就更好了吧?

构建资源程序集后,如何在我的应用程序的App.xaml中引用它?目前,我使用ResourceDictionary.MergedDictionaries来合并各个字典文件.如果我在一个程序集中有它们,我怎么能在xaml中引用它们?

.net wpf xaml resourcedictionary controltemplate

236
推荐指数
6
解决办法
13万
查看次数

查找资源字典时发生错误

我在App.xaml主程序集中有一个合并的资源字典,它结合了来自不同程序集的各种资源字典:Common和PresentationLayer.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Common;component/Themes/Button.xaml"/>
            <ResourceDictionary Source="/PresentationLayer;component/DataTemplates/AppointmentsDataTemplates.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

在运行时,资源字典中的样式将正确应用于控件.但是,在设计时不会应用样式,Visual Studio 2012会不断出现以下错误:

An error occurred while finding the resource dictionary "/Common;component/Themes/Button.xaml".
Run Code Online (Sandbox Code Playgroud)

并警告:

The resource "BannerButton" could not be resolved.
Run Code Online (Sandbox Code Playgroud)

我遇到过这篇文章,但问题仍然存在,尽管Build Action设置为Resource.此外,我在Visual Studio 2010或Expression Blend 4下运行时没有遇到此问题.主程序集肯定包含对Common程序集的引用,我没有更改Pack URI.

wpf visual-studio-2012

16
推荐指数
2
解决办法
2万
查看次数

为什么修改项目输出目录会导致:IOException未处理"无法找到资源'app.xaml'."

为了将项目设置合并到C++和C#项目的属性表中,构造了以下属性表:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!--
      Trying to support both C++ and C# projects by introducing derived 
      properties and setting the appropriate output properties.
  -->
  <PropertyGroup Label="UserMacros">
    <ProjectOrAssemblyName Condition="'$(AssemblyName)'==''">$(ProjectName)</ProjectOrAssemblyName>
    <ProjectOrAssemblyName Condition="'$(ProjectName)'==''">$(AssemblyName)</ProjectOrAssemblyName>
    <ShortPlatform Condition="'$(Platform)'=='Win32'">x86</ShortPlatform>
    <ShortPlatform Condition="'$(Platform)'=='x86'">x86</ShortPlatform>
    <ShortPlatform Condition="'$(Platform)'=='x64'">x64</ShortPlatform>
    <ShortPlatform Condition="'$(Platform)'=='AnyCPU'">AnyCPU</ShortPlatform>
  </PropertyGroup>
  <PropertyGroup>
    <OutputPath>$(OutputRelativePath)/$(ProjectOrAssemblyName)_$(ShortPlatform)_$(Configuration)/</OutputPath>        
    <BaseIntermediateOutputPath>$(OutputRelativePath)/Obj_Exe/$(ProjectOrAssemblyName)_$(ShortPlatform)</BaseIntermediateOutputPath>
    <IntermediateOutputPath>$(BaseIntermediateOutputPath)_$(Configuration)/</IntermediateOutputPath>
    <IntDir>$(IntermediateOutputPath)</IntDir>
    <OutDir>$(OutputPath)</OutDir>
  </PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)

此属性表将所有构建输出移动到单独的位置OutputRelativePath(在单独的属性表中定义或直接在项目文件中定义)外部目录,其中包含源代码以便于清理等.但是,在设置完成后,构建工作正常并且所有单元测试工作正常,很明显WPF可执行项目并不好,因为使用上面的属性表运行应用程序导致臭名昭着:

IOException was unhandled "Cannot locate resource 'app.xaml'."
Run Code Online (Sandbox Code Playgroud)

为什么更改输出路径会导致此错误?如何确定原因是项目构建输出路径?这可以在生成的代码中看到吗?我找不到?这不是一个错误吗?

注意:使用以下属性表工作,但仅当IntermediateOutputPath包含BaseIntermediateOutputPath时.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <OutputPath>$(OutputRelativePath)/$(AssemblyName)_$(Platform)_$(Configuration)</OutputPath>
    <BaseIntermediateOutputPath>$(OutputRelativePath)/Obj_Exe/$(AssemblyName)_$(Platform)</BaseIntermediateOutputPath>
    <IntermediateOutputPath>$(BaseIntermediateOutputPath)_$(Configuration)</IntermediateOutputPath>
  </PropertyGroup>
</Project> …
Run Code Online (Sandbox Code Playgroud)

c# msbuild wpf xaml visual-studio-2012

9
推荐指数
1
解决办法
1968
查看次数

WPF 资源字典构建操作

我在项目中有ResourceDictionary一个xaml名为 SylesResourceDictionary.xaml 的文件Class Library。这ResourceDictionary通过合并在不同视图中使用。

我是新手ResourceDictionary,不确定我是否以正确的方式做这件事。不同的文章建议不同的“构建操作”Page和“自定义工具”XamlIntelliSenseFileGenerator

  1. Build Action这个 xaml 文件应该是什么?我已将其设置为资源

  2. 应该是什么Custom Tool?我将其设置为 MSBuildCompile

  3. 我应该删除xaml.cs这个 xaml 文件吗?

c# wpf xaml resourcedictionary

3
推荐指数
1
解决办法
3855
查看次数