簡體   English   中英

具有屬性的分層數據綁定是否可能?

[英]Is hierarchical databinding with properties possible?

是否可以綁定到屬性的屬性? 這是我所擁有的:

    [Bindable(true)]
    public class DataClass
    {
        private string DescriptionValue = null;
        private Content DataContent Value = new Content();
        ....

        [Bindable(true)]
        public Content DataContent
        {
            get { return DataContent; }
            set { DataContent = value; }
        }

        [Bindable(true)]
        public string Description
        {
            get { return DescriptionValue; }
            set { DescriptionValue = value; }
        }
        ...
    }


    [Bindable(true)]
    public class Content
    {
        private object ContentValue = null;
        private Color StateBackColorValue;
        ...

        [Bindable(true)]
        public object Content
        {
            get { return ContentValue; }
            set { ContentValue = value; }
        }

        [Bindable(true)]
        public Color StateBackColor
        {
            get { return StateBackColorValue; }
            set { StateBackColorValue = value; }
        }
        ...
    }

是否可以將控件綁定到DataContent.Content或Content類的任何其他屬性? 我知道我可以在映射Content類屬性的DataContent類中引入屬性。 我只是想知道是否可以使用屬性進行分層數據綁定。

您正在執行哪種類型的數據綁定?

通過簡單的綁定(例如,將TextBox.Text綁定到單個對象),可以,可以使用“ Foo.Bar.SomeProp”作為成員。 對於PropertyGrid ,您可以使用[TypeConverter(typeof(ExpandableObjectConverter))]標記對象,然后它將起作用。

棘手的是列表綁定( DataGridView等); 在這里,不:它不容易變平。 你可以做,如果你竭盡全力ITypedList等),但它確實是不值得的-只需加墊片性質父:

public string ChildName {
   get {return child == null ? "" : child.Name;} // and setter if you want
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM