gpt4 book ai didi

c# - 作为基础的通用类导致 XAML 错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:12:49 25 4
gpt4 key购买 nike

我有类 customerproduct。它们的相似之处在于 Base Record 类。但是,Base Record 中的类型始终取决于它是customer 还是product。因此,我一般创建了 Base Record

一旦 customerproduct 继承自 Base Record ,我的 WPF 项目就会出现 XMAL 错误。不幸的是,我不知道这是为什么,为什么我写在这里 ;)

BaseRecord 的头部:

public abstract class BaseRecord<T> : Notify where T : class, new()

客户负责人:

public class Customer : BaseRecord<Data_Layer.Customer>

XAML 错误:

   Unknown build error, 'Cannot resolve dependency to assembly 'Version=1.0.0.0,  Culture=neutral, PublicKeyToken=null' 
because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on
demand through the ReflectionOnlyAssemblyResolve event.'

和:

The tag 'CustomerAddWindow' does not exist in XML namespace 'clr-namespace:Business_Layer.Windows.Customer;assembly=Business_Layer'

如果我使类 BaseRecord 不是通用的,一切都按我的意愿工作。

在 XAML 中,我实例化

<local:Customer x:Key="CustomerViewModel "/>

新年快乐。

最佳答案

XAML 不直接支持泛型。

有一些旨在解决这个问题的副项目,但我总是选择忍受它。它确实从未妨碍我的应用程序架构。

一个我认为简单有效的解决方法是拥有一个解决泛型问题的中间继承类。

例如,

public abstract class BaseRecord<T> : Notify where T : class, new()

public abstract class CustomerBase : BaseRecord<Data_Layer.Customer>

public class Customer : CustomerBase

我目前正在开发一个 WPF 应用程序,我的 XAML 中不需要任何泛型。

我在 xaml 代码隐藏中有零代码。确实,由于一些自定义,我的基本窗口类具有所有与 UI 相关的代码。

如果您遵循 MVVM 架构,那么很可能是您的基本窗口中的一个属性的通用架构应该很可能属于 ViewModel 类。

关于c# - 作为基础的通用类导致 XAML 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27703216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com