2017-11-02 3 views
0

私はこのように、クラスで定義され、そのプロパティを持つPropertyGridコントロールを持っている:ExtendedToolkit PropertyGridコントロールでプロパティを表示/非表示することはできますか?

[DisplayName("Display Company Logo")] 
[PropertyOrder(5)] 
public bool HasLogo { get; set; } 

[DisplayName("Logo File Path")] 
[PropertyOrder(6)] 
[Browsable(true)] 
[Editor(typeof(FilePickerEditor), typeof(FilePickerEditor))] 
public string LogoFilePath { get; set; } 

はHasLogoがチェックされているかどうかに応じて、LogoFilePathプロパティを非表示にすることが可能ですか?または、少なくともカスタムFilePickerEditorを読み取り専用にします。

答えて

0

私はそれを行動を使って解決することができました。

<toolkitExt:PropertyGrid Tag="DependentVisibility,HasLogo,LogoFilePath" 
         SelectedObject="{Binding PropertyGridSourceObjectUserPreferences, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> 
    <i:Interaction.Behaviors> 
     <b:PropertyGridBehavior/> 
    </i:Interaction.Behaviors> 
</toolkitExt:PropertyGrid> 

行動:

public class PropertyGridBehavior : Behavior<PropertyGrid> 
{ 
    string _tag; 
    List<Tuple<string, string, string>> _dependentVisibilityList; 
    PropertyGrid _propertyGrid; 

    protected override void OnAttached() 
    { 
     _propertyGrid = AssociatedObject as PropertyGrid; 
     _dependentVisibilityList = new List<Tuple<string, string, string>>(); 

     if(_propertyGrid.Tag !=null) 
     { 
      _tag = _propertyGrid.Tag.ToString(); 

      foreach(var v in _tag.Split(';')) 
      { 
       if (v.Split(',').Count() != 3) return; 
       _dependentVisibilityList.Add(new Tuple<string, string, string>(v.Split(',')[0], v.Split(',')[1], v.Split(',')[2])); 
      } 
     } 

     _propertyGrid.Loaded += _propertyGrid_Loaded; 
     _propertyGrid.PropertyValueChanged += PropertyGrid_PropertyValueChanged; 
    } 

    private void _propertyGrid_Loaded(object sender, RoutedEventArgs e) 
    { 
     foreach(var v in _propertyGrid.Properties as PropertyItemCollection) 
     { 
      PropertyItemDependencyVisibilitySet(v.PropertyName, v.Value); 
     } 
    } 

    private void PropertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e) 
    { 
     if (e.NewValue.GetType().Equals(typeof(bool))) 
     { 
      PropertyItem originalSource = (PropertyItem)e.OriginalSource; 
      PropertyItemDependencyVisibilitySet(originalSource.PropertyName, (bool)e.NewValue); 
     } 
    } 

    private void PropertyItemDependencyVisibilitySet(string propertyName, object propertyValue) 
    { 
     try 
     { 
      Tuple<string, string, string> dependentVisibilityItem = _dependentVisibilityList.Where(x => x.Item1 == "DependentVisibility" && x.Item2 == propertyName).FirstOrDefault(); 

      if (dependentVisibilityItem != null) 
      { 
       PropertyItemCollection propertyCollection = _propertyGrid.Properties as PropertyItemCollection; 
       PropertyItem propertyItemDestination = propertyCollection.Where(x => x.PropertyName == dependentVisibilityItem.Item3).FirstOrDefault(); 

       if (propertyItemDestination != null) propertyItemDestination.Visibility = (bool) propertyValue ? Visibility.Visible : Visibility.Collapsed; 
      } 
     } 
     catch 
     { 
     } 
    } 
} 
PropertyGridのは、次のように定義されました
関連する問題