2016-06-30 2 views
0

나는 현재와 같은 종속성 속성이 있습니다CollectionPropertiesShouldBeReadOnly 및 종속성 속성

public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyPropertyDefaults", typeof(ICollection<string>), typeof(MyPanel), new PropertyMetadata(new List<string>())); 

public ICollection<string> MyProperty 
{ 
    get 
    { 
     return GetValue(MyPropertyProperty) as ICollection<string>; 
    } 

    set 
    { 
     this.SetValue(MyPropertyProperty, value); 
    } 
} 

목적이 서브 패널은 서브 패널을 조작하는 것으로, 바인딩을 통해 목록을 전달됩니다 다음 부모가 나중에 읽을 수 있다는 것입니다 . 예 :

<xaml:MyPanel MyProperty="{Binding MyPropertyList}" /> 

그러나,의 FxCop은 CollectionPropertiesShouldBeReadOnly를보고하고 나는 재산에 필요한 세터를 제거해야합니다. 이 문제를 어떻게 해결할 수 있습니까? 내가하는 일을하는 올바른 방법은 무엇입니까?

답변

0

이 같은 비공개로 세터를 선언 : 가능

public class MyPanel : Panel 
{ 
    public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyPropertyDefaults", typeof(ICollection<string>), typeof(MyPanel), new PropertyMetadata(new List<string>())); 

    public ICollection<string> MyProperty 
    { 
     get 
     { 
      return GetValue(MyPropertyProperty) as ICollection<string>; 
     } 

     private set 
     { 
      this.SetValue(MyPropertyProperty, value); 
     } 
    } 
} 
+0

하지? 'MyPanel.MyProperty'속성에는 액세스 가능한 액세스 접근자가 없으므로 설정할 수 없습니다. – Detritus

+0

위와 같이 작동합니까? – Udo

+0

아니요, 인터페이스를 사용하려면 인터페이스가 공용이어야합니다. 나는 문제가 내가 사용하고있는 컬렉션에 있다고 생각한다. 나는 직접 컬렉션을 전달해서는 안된다. 그러나 다른 방법으로? – Detritus