다음을 통해 공유


속성 표 확장성

디자이너 내에서 지정된 활동을 선택할 때 표시되는 속성 표를 사용자 지정하여 풍부한 편집 환경을 만들 수 있습니다. PropertyGridExtensibility 샘플은 이 작업을 수행하는 방법을 보여 줍니다.

입증합니다

워크플로 디자이너 속성 그리드 확장성.

토론

속성 그리드를 확장하기 위해 개발자는 속성 그리드 편집기의 인라인 모양을 사용자 지정하거나 고급 편집 화면에 표시되는 대화 상자를 제공하는 옵션을 제공합니다. 이 샘플에는 두 개의 다른 편집기가 있습니다. 인라인 편집기 및 대화 상자 편집기

인라인 편집기

인라인 편집기 샘플은 다음을 보여 줍니다.

  • 에서 PropertyValueEditor파생되는 형식을 만듭니다.

  • 생성자 InlineEditorTemplate 에서 값은 WPF(Windows Presentation Foundation) 데이터 템플릿을 사용하여 설정됩니다. XAML 템플릿에 바인딩할 수 있지만 이 샘플에서는 코드가 데이터 바인딩을 초기화하는 데 사용됩니다.

  • 데이터 템플릿에는 속성 표에 렌더링된 항목의 데이터 컨텍스트 PropertyValue 가 있습니다. 다음 코드(CustomInlineEditor.cs)를 보면, 이 컨텍스트가 이후에 Value 속성에 바인딩됩니다.

    FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));
    FrameworkElementFactory slider = new FrameworkElementFactory(typeof(Slider));
    Binding sliderBinding = new Binding("Value");
    sliderBinding.Mode = BindingMode.TwoWay;
    slider.SetValue(Slider.MinimumProperty, 0.0);
    slider.SetValue(Slider.MaximumProperty, 100.0);
    slider.SetValue(Slider.ValueProperty, sliderBinding);
    stack.AppendChild(slider);
    
  • 활동과 디자이너가 동일한 어셈블리에 있으므로 활동 디자이너 특성의 등록은 SimpleCodeActivity.cs 다음 예제와 같이 활동 자체의 정적 생성자에서 수행됩니다.

    static SimpleCodeActivity()
    {
        AttributeTableBuilder builder = new AttributeTableBuilder();
        builder.AddCustomAttributes(typeof(SimpleCodeActivity), "RepeatCount", new EditorAttribute(typeof(CustomInlineEditor), typeof(PropertyValueEditor)));
        builder.AddCustomAttributes(typeof(SimpleCodeActivity), "FileName", new EditorAttribute(typeof(FilePickerEditor), typeof(DialogPropertyValueEditor)));
        MetadataStore.AddAttributeTable(builder.CreateTable());
    }
    

대화 상자 편집기

대화 상자 편집기 샘플은 다음을 보여 줍니다.

  1. 에서 DialogPropertyValueEditor파생되는 형식을 만듭니다.

  2. InlineEditorTemplate WPF 데이터 템플릿을 사용하여 생성자의 값을 설정합니다. XAML에서 만들 수 있지만 이 샘플에서는 코드로 만들어집니다.

  3. 데이터 템플릿에는 속성 표에 렌더링된 항목의 데이터 컨텍스트 PropertyValue 가 있습니다. 다음 코드에서는 this가 Value 속성에 바인딩됩니다. EditModeSwitchButton를 포함하여 FilePickerEditor.cs에서 대화 상자를 올리는 버튼을 제공하는 것이 중요합니다.

    this.InlineEditorTemplate = new DataTemplate();
    
    FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));
    stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
    FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label));
    Binding labelBinding = new Binding("Value");
    label.SetValue(Label.ContentProperty, labelBinding);
    label.SetValue(Label.MaxWidthProperty, 90.0);
    
    stack.AppendChild(label);
    
    FrameworkElementFactory editModeSwitch = new FrameworkElementFactory(typeof(EditModeSwitchButton));
    
    editModeSwitch.SetValue(EditModeSwitchButton.TargetEditModeProperty, PropertyContainerEditMode.Dialog);
    
    stack.AppendChild(editModeSwitch);
    
    this.InlineEditorTemplate.VisualTree = stack;
    
  4. 디자이너 형식의 ShowDialog 메서드를 재정의하여 대화 상자의 표시를 처리합니다. 이 샘플에서는 기본 FileDialog 값이 표시됩니다.

    public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
    {
        Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
        if (ofd.ShowDialog() == true)
        {
            propertyValue.Value = ofd.FileName;
        }
    }
    
  5. 활동과 디자이너가 동일한 어셈블리에 있으므로 활동 디자이너 특성의 등록은 SimpleCodeActivity.cs 다음 예제와 같이 활동 자체의 정적 생성자에서 수행됩니다.

    static SimpleCodeActivity()
    {
        AttributeTableBuilder builder = new AttributeTableBuilder();
        builder.AddCustomAttributes(typeof(SimpleCodeActivity), "RepeatCount", new EditorAttribute(typeof(CustomInlineEditor), typeof(PropertyValueEditor)));
        builder.AddCustomAttributes(typeof(SimpleCodeActivity), "FileName", new EditorAttribute(typeof(FilePickerEditor), typeof(DialogPropertyValueEditor)));
        MetadataStore.AddAttributeTable(builder.CreateTable());
    }
    

샘플을 설정, 빌드 및 실행하려면

  1. 솔루션을 빌드한 다음 Workflow1.xaml을 엽니다.

  2. 도구 상자에서 디자이너 캔버스로 SimpleCodeActivity 를 끌어옵니다.

  3. SimpleCodeActivity를 클릭한 다음 슬라이더 컨트롤과 파일 선택 컨트롤이 있는 속성 그리드를 엽니다.