English 中文(简体)
二级女性法郎 跨项目的用户
原标题:Subclassing WPF UserControl doesn t work across projects

Hi I ve在以下信息的基础上建立了一些次级用户控制:。 但是,我却对一个问题打上了阴影。

在此,我的一个基类是测试UserControl项目。

namespace TestUserControl
{
    public class BaseDataGridControl : UserControl
    {
        protected BaseDataGridControl()
        {
        }
    }
}

并在此列出我的具体类别;

<view:BaseDataGridControl x:Class="TestUserControl.Concrete"
         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:view="clr-namespace:TestUserControl"      
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Button Height="20" Width="60" Margin="12,12,228,268" />
    </Grid>
</view:BaseDataGridControl>

而这一控制法则似乎如此。

public partial class Concrete : BaseDataGridControl
{
    public Concrete()
    {
        InitializeComponent();
    }
}

我可以在同一个测试UserControl项目的一个窗口上放弃我的具体班子,没有任何问题。

<Window x:Class="TestUserControl.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:TestUserControl">
    <Grid>
        <my:Concrete HorizontalAlignment="Left" Margin="88,39,0,0" x:Name="concrete1" VerticalAlignment="Top" />
    </Grid>
</Window>

this all works fine.

问题在于我试图在另一个项目中使用具体类别。

如果我设立另一个项目(WPFApplication1),并根据具体类别(例如)设立一个班级。

namespace WpfApplication1
{
    public class SubClass : Concrete
    {
    }
}

when i attempt to drop this onto a window in the WPFApplication1 project I get an ;

“由于收集工作发生变化,统计员无效”

如果我试图通过XAML加以补充,我就获得一个信息。

构成部分WpfApplication1。 SubClass没有URI /RedelUserControl;component/concrete.xaml。

error message.

The WPFApplication1 project has a reference to the TestUserControl project.

是否有任何人对该项目内的这项工作为什么在项目内界定了用户控制,但一旦你试图将其归入一个单独的项目,它是否失败了?

我在VS2010和VS11 beta试图这样做,结果同样坏。

我不想在班级的建筑商中进行反思或获取任何收集材料,这部法典就是你在这里看到的。

I ve got test project that demonstrates this problem, if it would help?

感谢......。

问题回答

类似问题。 我有一个与我的基建和股一起的项目,有几个项目是用户控制。 (我们称之为“基本倡议”项目。) 在我的第二个项目中(我们称“SubProj”)。 我可以补充一下它的内容,并将之添加到视觉演播室的xaml身上,但我可以使用Blend来看到这些变化。 现在,我可以把它用于我的一些更为复杂的编辑工作。

它产生错误“[此处注明名称]在名称空间中不存在”

我发现的定点可能允许你在子项目中继承。

您不是试图直接从参考议会中使用这一类,而是能够利用链接把该守则添加到你目前的大会。 链接使得控制如同在现有的项目中一样,但守则来自基建项目。 对它的任何改动都影响到所有环节。 如果没有跨项目的问题,你就能够从当地继承。

这里请你:

  1. Create the base control in your "BaseUI" project
  2. Right click your "SubProj" and add an existing item
  3. Hunt down the .xaml file from the "BaseUI" project for the user control you want.
  4. Click the arrow next to the "Add" button and choose "Add as link"




相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签