하위 노드에서 parentnode'e 속성을 표시해야하는 XtratreeList (DevExress)에 대한 bindingList에 몇 가지 속성이 있습니다. 다음 코드가 있습니다. 자녀의 - ProductType
속성 변경은 기본적으로 ProductType
부모 노드 속성과 ColorProductType
때INotifyPropertyChanged를 사용하여 파생 속성을 업데이트하는 방법
public abstract class ClassBase : INotifyPropertyChanged
{
protected static int initialId = 0;
private int id;
private int parentID;
private string productName;
private string productType;
private string colorProductType;
private void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public int ID
{
get { return id; }
set
{
if (id == value)
return;
id = value;
RaisePropertyChanged("ID");
}
}
public int ParentID
{
get { return parentID; }
set
{
if (parentID == value)
return;
parentID = value;
RaisePropertyChanged("ParentID");
}
}
public string ProductName
{
get { return productName; }
set
{
if (productName == value)
return;
productName = value;
RaisePropertyChanged("ProductName");
}
}
public string ProductType
{
get { return productType; }
set
{
if (productType == value)
return;
productType = value;
RaisePropertyChanged("ProductType");
RaisePropertyChanged("ColorProductType");
}
}
public string ColorProductType
{
get { return colorProductType ; }
set
{
if (colorProductType == value)
return;
colorProductType = value;
RaisePropertyChanged("ColorProductType");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}`
내 요구 사항은 변경된 ColorProductType
속성을 가지고있다. 그래서 부모의 재산을 바꾸면 자녀를 바꿀 필요가 있습니다. 나는이 두 속성을 2 개의 텍스트 상자에 바인딩했습니다. 따라서 부모 소품을 변경하면 두 텍스트 상자가 모두 변경되지만 반대의 경우도 마찬가지입니다. 부모 내의 RaisePropertyChanged("ColorProductType");
이 작동하지 않습니다. colorproducttype
이 null 인 경우 문제가 무엇입니까?
덕분에, 나는 잔인한 방법을 사용 할 수 있습니다 어떤 경우에는 colorprodtype을 설정하기위한 별도의 속성이 필요합니다. 그러나 사용자가 Producttype (부모의 소품)을 업데이트하면 자녀의 속성을 덮어 씁니다. colorprodtype 속성을 유지하고 Producttype 내에서 colorproducttype을 업데이트 할 것을 제안 하시겠습니까? – RashMans
@WittyWoman 예. 내가 게시 한 두 번째 코드 샘플은 충분히 잘 작동한다고 생각합니다. 그것으로부터'ColorProductType'을 생략했지만 실제 코드에 그대로 두어야합니다. 그런 다음 사용자가'ColorProductType'을 업데이트하면 예상대로 작동하고, 사용자가'ProductType'을 업데이트하면 setter의 코드가'ColorProductType'을 재설정합니다. 만약 당신이 더 분리 된 것을 유지하고 싶다면 위에 게시 한 이벤트 처리 접근법을 사용하고'ProductType' 설정자에서'ColorProductType'을 변경하는 부작용을 피할 수 있습니다. –
나는 그것이 colorproducttype을 업데이트하고 아이의 textbox에 리 바인딩하는 것만 큼 좋았 더라면 좋겠다.하지만 부모가 업데이트되었을 때 자식에 대한 바인딩 목록을 업데이트해야한다. 바인딩 목록의 listchanged 이벤트는 부모의 자식을 찾아서 목록의 각 속성을 변경하고 수정합니다. 그 꽤 매뉴얼지만 다른 어떤 방법을 모른다. – RashMans