该组件没有标识的URI的资源 [英] The component does not have a resource identified by the uri

查看:3107
本文介绍了该组件没有标识的URI的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个通用的DataGrid在所有我的意见/用户控件使用。

I want to create a Generic DataGrid to use on all my Views/UserControls.

这是我的结构:

类库名为核心

名为ViewBase

public class ViewBase : UserControl
{
    public ViewBase()
    {
    }   

    //Rest of Methods and Properties
}

类库名为控制

用户控件名为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背后:

Code Behind:

using Core;

public partial class GridView : ViewBase
{
    public GridView ()
    {
        InitializeComponent();
    }
}

然后就是WPF Aplication称为WPFApp:

Then is the WPF Aplication called "WPFApp":

名为查看

using Controls;

public class View : GridView
{
    public View()
    {
        InitializeComponent();
    }
}

我的整个想法是使用的GridView ,我需要一个的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?

推荐答案

我是做什么用的相同的结果非常相似。我有一个包含WPF控件称为UsageControl(XAML伴随xaml.cs文件)一架C#类库。在一个单独的C#项目(即单独的DLL)我创建了一个C#的 CPUUsageControl其中的继承从UsageControl,而是先把自己的旋转就可以了。当我试图使用CpuUsageControl对我的一个视图我给你做了同样的错误。

I was doing something very similar with the same result. I had one C# class library that contained a WPF control called UsageControl (xaml with accompanying xaml.cs file). In a separate C# project(i.e. separate dll) I created a C# class CPUUsageControl which inherited from UsageControl, but put its own spin on it. When i tried to use the CpuUsageControl on one of my views i got the same error you did.

我做了什么来解决,而不是创建一个从基Control继承一个类,是在我的单独组件,我创建了一个新的WPF控件的包含基本控件。后来我把载于CpuUsage类到WpfCpuUsageControl的code背后的逻辑所有。我能够使用这个对象是我的所有其他控件就好了。

What i did to fix that was in my seperate assembly, instead of creating a class that inherited from the base control, i created a new WPF Control that contained the base control. I then put all of the logic that was contained in the CpuUsage class into the WpfCpuUsageControl's code behind. I was able to use this object is all of my other controls just fine.

有关的控制的GridView我将创建一个新的 WPF用户控件,把它叫做GridView和使其包含ViewBase作为电网控制的内容.Inside的ViewBase的内容放到你的DataGrid中,像这样的:

For your Control "GridView" i would create a new WPF user control, call it GridView and make it contain a "ViewBase" as the content of the Grid control.Inside of the ViewBase's content put in your DataGrid, like this:

<UserControl....>
    <Grid>
        <ViewBase name="vBase">
            <DataGrid name="dGrid" />
        </ViewBase>
    </Grid>
</UserControl>

这也是看不出来的,我认为你需要ViewBase从用户控件直接继承。如果你想对你的控制有一定的属性和方法,为什么不只是做一个BASECONTROL类(即不从任何人,但对象继承),并有未来的控制继承它。也许是一个抽象基类或接口是你以后有什么。

It is also not apparent to me that you need ViewBase to inherit from UserControl directly. If all you want are for your controls to have certain properties and method why not just make a BaseControl class (that does not inherit from anyone but object) and have future controls inherit from it. Perhaps an abstract base class or interface is what your after.

有关MVVM WPF项目,我通常有它实现INotifyPropertyChanged对我来说是BaseViewModel所以我没有做同样的code无处不在。

For MVVM WPF projects, i typically have a BaseViewModel which implements INotifyPropertyChanged for me so i dont have to do that same code everywhere.

祝你好运,我知道这个问题是一个巨大的痛苦要弄清楚。异常消息和谷歌是最无助!

Best of luck, i know this problem was a huge pain to figure out. The exception message and google are most unhelpful!

这篇关于该组件没有标识的URI的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆