2010-05-12 4 views
2

wpf PropertyGrid (PG) 컨트롤에서 작업 중이며 컬렉션 유형 (IList, ObservableCollection 등) 속성을 지원하는 PG가 필요합니다. 나는 (컬렉션의) 선택한 항목을 추적하고이를 클라이언트에게 전달하는 방법에 대해서는 다소 혼란 스럽다.WPF PropertyGrid - 컬렉션에 대한 지원 추가

아이디어가 있으십니까?

솔루션에서 오픈 소스 WPF PropertyGrid (http://www.codeplex.com/wpg)를 사용하는 경우 변경 사항을 컨트롤에 다시 구현합니다.

답변

2

답변이 없으므로이 작업을 수행하는 데 직접적인 방법이 없음을 입증하지 못합니다.

이 같은 RelatedItemSourcePropertyAttribute라는 이름의 속성을 생성 - - 그래서 난이 기능이 방법을 구현

/// <summary> 
/// Attribute to identify the related item source property. 
/// Note: Property should be of IEnumerable type 
/// </summary> 
[global::System.AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = false)] 
public sealed class RelatedItemSourcePropertyAttribute : Attribute 
{ 
    // See the attribute guidelines at 
    // http://go.microsoft.com/fwlink/?LinkId=85236 

    private string relatedPropertyName; 
    public static readonly RelatedItemSourcePropertyAttribute Default = new RelatedItemSourcePropertyAttribute(string.Empty); 

    /// <summary> 
    /// Initializes a new instance of the <see cref="RelatedPropertyAttribute"/> class. 
    /// </summary> 
    /// <param name="relatedPropertyName">Name of the related property.</param> 
    public RelatedItemSourcePropertyAttribute(string relatedPropertyName) 
    { 
     this.relatedPropertyName = relatedPropertyName; 
    } 

    /// <summary> 
    /// Gets a value indicating whether [related property name]. 
    /// </summary> 
    /// <value><c>true</c> if [related property name]; otherwise, <c>false</c>.</value> 
    public string RelatedPropertyName 
    { 
     get { return relatedPropertyName; } 
    } 

    /// <summary> 
    /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. 
    /// </summary> 
    /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> 
    /// <returns> 
    ///  <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>. 
    /// </returns> 
    public override bool Equals(object obj) 
    { 
     if (!(obj is RelatedItemSourcePropertyAttribute)) 
      return false; 
     if (obj == this) 
      return true; 
     return ((RelatedItemSourcePropertyAttribute)obj).relatedPropertyName == relatedPropertyName; 
    } 

    /// <summary> 
    /// Returns a hash code for this instance. 
    /// </summary> 
    /// <returns> 
    /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
    /// </returns> 
    public override int GetHashCode() 
    { 
     return relatedPropertyName.GetHashCode(); 
    } 

    /// <summary> 
    /// When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. 
    /// </summary> 
    /// <returns> 
    /// true if this instance is the default attribute for the class; otherwise, false. 
    /// </returns> 
    public override bool IsDefaultAttribute() 
    { 
     return relatedPropertyName == RelatedItemSourcePropertyAttribute.Default.relatedPropertyName; 
    } 
} 

값 관련 항목 소스 속성 (의 속성 이름을 걸릴 것이 속성은을 채우기 위해 사용됩니다 쓰러지 다). 이런 식으로 사용됩니다 -

[RelatedItemSourceProperty("UnitNames")] 
    public virtual string SelectedUnit 
    { 
     get { return (string)GetValue(SelectedUnitProperty); } 
     set { SetValue(SelectedUnitProperty, value); } 
    } 
    public static readonly DependencyProperty SelectedUnitProperty = 
     DependencyProperty.Register("SelectedUnit", typeof(string), typeof(BaseControl), 
     new UIPropertyMetadata(string.Empty, new PropertyChangedCallback(SelectedUnitChangedCallBack))); 


    public virtual ObservableCollection<string> UnitNames 
    { 
     get { return (ObservableCollection<string>)GetValue(UnitNamesProperty); } 
     set { SetValue(UnitNamesProperty, value); } 
    } 
    public static readonly DependencyProperty UnitNamesProperty = 
     DependencyProperty.Register("UnitNames", typeof(ObservableCollection<string>), 
     typeof(BaseProperties), new PropertyMetadata(null)); //Validation 

그리고 나서 속성 I에서 관련 항목 소스 속성을 콤보 상자로 바인딩합니다.

더 나은 해결책을 보려면 다음을보십시오.

+0

나는 같은 상황에 있습니다. WPG에 컬렉션 지원을 추가해야합니다. 나는이 코드를 구현했다. 그러나 나는 충분하지 않다고 생각한다. –

+0

@Bahadir arslan : 직면 한 정확한 문제/오류에 대한 자세한 내용을 제공 할 수 있습니까? 내 응용 프로그램에서 동일한 것을 구현하고 잘 작동합니다. – akjoshi

+0

속성을 목록으로 표시해야합니다. 예를 들어 사용자는 도시 목록에서 도시를 선택할 수 있습니다. 그래서 나는 당신의 게시물을 찾았습니다. 하지만 나는 얻을 수 없었다 :) 당신의 솔루션을 먼저 구현할 때 의존성 속성이 속성 표에 표시되고 두 번째로 TextBox로 표시된 내 속성 (SelectedUnitProperty)이 나타납니다. 그 후 WPGTemplates.xaml을 찾고 IList 형식의 템플릿을 편집했습니다. 그래서 나는 콤보 박스로 내 목록을 보여줄 수있다 :) –

관련 문제