Reputation:
I have 2 assembly projects and I am trying to reference BooksGrid in the Library.Books project From Library.UI assembly project but I keep
Getting the following Exception “ Cannot locate resource ‘grid/booksgridlist.xaml” but the file exists as explained below.
I have tried almost everything as explained in other similar questions but nothing worked. am i doing something wrong ? Any help is well appreciated in advance.
BooksGrid.cs in Library.Books Assembly project . Note: BooksGridList.xaml is resource file located in this same project. Absolute Path for BooksGrid.cs: C:\Library.Books\Grids\BooksGrid.cs Absolute Path for BooksGridList.xaml: C:\Library.Books\Grids\BooksGridList.xaml and build action for this file is set to “Resource” and Copy to output Directory is set to “Do not Copy” -- I also tried "copy always" but that did not work. I cleaned the project and build it again but still it did not work.
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")
};
}
}
}
BooksSelector.xaml in Library.UI assembly project Absolute Path for 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>
Upvotes: 2
Views: 3068
Reputation: 2097
Why you are not doing this in xaml.
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Library.Books;component/Grids/BooksGridList.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Upvotes: 3