我有2个装配项目,我试图在Library.Books项目中引用BooksGrid来自Library.UI装配项目,但我保留
获得以下异常“无法找到资源'grid / booksgridlist.xaml”,但该文件存在,如下所述。
我已经尝试了其他类似问题中解释的几乎所有内容但没有任何效果。难道我做错了什么 ?任何帮助都提前得到很好的赞赏。
Library.Books汇编项目中的BooksGrid.cs。注意:BooksGridList.xaml是位于同一项目中的资源文件。 BooksGrid.cs的绝对路径:C:\ Library.Books \ Grids \ BooksGrid.cs BooksGridList.xaml的绝对路径:C:\ Library.Books \ Grids \ BooksGridList.xaml和build 此文件的操作设置为“资源”,复制到输出目录设置为“不复制” - 我也尝试“始终复制”但这不起作用。我清理了项目并再次构建它但仍然没有用。
namespace Library.Books.Grids
{
public class BooksGrid
{
public BooksGrid()
{
AutoGenerateColumns = false;
CanUserAddRows = false;
IsReadOnly = true;
ResourceDictionary dictionary = new ResourceDictionary
{
Source = new Uri("pack://application:,,,/Library.Books;component/Grids/BooksGridList.xaml")
};
}
}
}
Library.UI程序集项目中的BooksSelector.xaml BooksSelector.xaml的绝对路径:C:\ Library.UI \ Library.UI.BooksSelector
<UserControl x:Class=" Library.UI.BooksSelector" DataContext="{Binding RelativeSource= {RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ex="clr-namespace:Library.Books.Grids;assembly=Library.Books"
xmlns:dx="clr-namespace:Library.Sections.Converters;assembly=Library.Sections">
<UserControl.Resources>
<dx:FormattingConverter x:Key="ValueConverter" />
</UserControl.Resources>
<Grid>
<ex:BooksGrid Name="LibraryCtrl" Grid.Column="0" Grid.Row="1" TabIndex="2" SelectionChanged="LibraryCtrl_OnSelectionChanged" PropertyChanged="LibraryCtrl_OnPropertyChanged">
<ex:BooksGrid.Columns >
<DataGridTextColumn Width="100" Header="ISBN" SortMemberPath="ISBN" Binding="{Binding Path=ISBN}" />
<DataGridTextColumn Width="180" Header="Name" SortMemberPath="Name" Binding="{Binding Path=Name}" />
<DataGridTextColumn Visibility="Collapsed" Width="70" Header="LibraryCode" SortMemberPath="LibraryCode" Binding="{Binding Path=LibraryCode}" />
</ex:BooksGrid.Columns>
</ex:BooksGrid>
</Grid>
</UserControl>
答案 0 :(得分:3)
为什么你不在xaml中这样做。
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Library.Books;component/Grids/BooksGridList.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>