I want to create a Generic DataGrid to use on all my Views/UserControls.
This is my structure:
Class Library
called "Core"
:
Class
called "ViewBase"
:
public class ViewBase : UserControl { public ViewBase() { } //Rest of Methods and Properties }
Class Library
called "Controls"
:
UserControl
Called "GridView"
:
XAML:
<vb:ViewBase x:Class="Controls.GridView" 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:vb="clr-namespace:Core;assembly=Core"> <Grid> <DataGrid></DataGrid> </Grid> </vb:ViewBase>
Code Behind:
using Core; public partial class GridView : ViewBase { public GridView () { InitializeComponent(); } }
Then is the WPF Aplication called "WPFApp":
Class
called "View"
:
using Controls; public class View : GridView { public View() { InitializeComponent(); } }
My whole idea is to use GridView
where i need a DataGrid
.
When i run the application i get this error:
"The component 'WpfApp.View' does not have a resource identified by the URI '/Controls;component/GridView.xaml'."
What am i doing wrong?
Is this the correct approach or am i way off?
Frustratingly, I had exactly this error and spent forever trying to work out the cause. For me, it was once working but then I made some very minor changes to the XAML of the derived control, and the compiler started giving that error message. Short solution, cutting out many hours of trying to figure it out: shut down Visual Studio and re-opened it, recompiled, problem magically went away! (This is VS2012 Pro) Just added this in case anyone reading is going round in circles trying to find a non-existent problem with their code. Might be worth trying the "IT Crowd solution" first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With