【问题标题】:How to make composite User Control VB.NET如何制作复合用户控件 VB.NET
【发布时间】:2021-02-07 21:51:42
【问题描述】:
<Serializable()>    
Public Class PersonNameOnly
   
    Private p_Name As String = ""
    Public Sub New()
        ' needed for deserialization
    End Sub

    Public Property Name As String
        Get
            Return p_Name
        End Get
        Set(value As String)
            p_Name = value
        End Set
    End Property
End Class 

[WinForm]

上面的PersonNameOnly 类是绑定在PersonUsercontrolForPersonWithNameOnly 用户控件上的BindingSource 类型,名称绑定到Textbox

MainUsercontrolForPersonWithNameOnly 有一个PersonUsercontrolForPersonWithNameOnly 的集合

以上所有功能在现有应用程序中都可以正常工作。

我需要 new 来创建一个新表单 MainUsercontrolForPersonWITHIMAGE 所以我创建了一个新的 UserControl 继承 PersonUsercontrolForPersonWithNameOnly 并添加了一个 Label 来保存 ImageUrl,所以这就是我到目前为止所做的.

<Serializable()>
Public Class PersonWITHIMAGE
    Inherits PersonNameOnly
    Private p_ImageUrl As String = ""
    Public Sub New()
        ' needed for deserialization
    End Sub

    Public Property ImageUrl As String
        Get
            Return p_ImageUrl
        End Get
        Set(value As String)
            p_ImageUrl = value
        End Set
    End Property
End Class 

[WinForm]

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
Partial Class PersonUsercontrolForPersonWITHIMAGE 
    Inherits PersonUsercontrolForPersonWithNameOnly 

如何将两个数据绑定合并为一个源仅限用户控制。

如何将两个数据绑定合并为一次复合形式?

【问题讨论】:

    标签: vb.net winforms data-binding


    【解决方案1】:

    您似乎想要绑定到两种不同的类型,其中一种是另一种的基本类型。我认为你做不到。

    但是您是否考虑过使用接口(例如IPersonUsercontrolForPerson)并将每个类都基于它?这应该会打开抽象控件绑定的可能性。

    免责声明!这个答案应该作为一个起点,因为我实际上并没有为你编写测试/答案。但这就是我开始寻找的地方。

    【讨论】:

    • 谢谢,请问您有示例或示例的链接吗?
    • 我确实错过了一个关键细节,即类是 用于 XML,所以我在接口方面遇到了一些问题,这就是我寻找替代解决方案的原因
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    相关资源
    最近更新 更多