0

WF 4.5 워크 플로 활동에서 폴더 찾아보기를 구현하려고하지만 줄임표 단추가 표시되지 않고 거의 아무 일도 발생하지 않습니다. Windows 워크 플로 디자이너 4.5 (폴더 찾아보기)의 UITypeEditor

내 UITypeEditor 클래스입니다 :

public class BrowseForFolderEditor : UITypeEditor 
{ 
    public override object EditValue(ITypeDescriptorContext context, 
     IServiceProvider provider, object value) 
    { 
     string folderName = string.Empty; 
     BrowseForFolderAttribute browseForFolderAttribute = null; 

     if (value is string) 
     { 
      if (context?.PropertyDescriptor != null) 
      { 
       browseForFolderAttribute = 
        (BrowseForFolderAttribute) 
       context.PropertyDescriptor.Attributes[typeof(BrowseForFolderAttribute)]; 
      } 

      var browse = new FolderBrowserDialogEx 
      { 
       Description = browseForFolderAttribute?.Description, 
       ShowNewFolderButton = true, 
       ShowEditBox = true, 
       SelectedPath = folderName, 
       ShowFullPathInEditBox = false, 
       RootFolder = Environment.SpecialFolder.MyComputer 
      }; 

      var result = browse.ShowDialog(); 

      if (result == DialogResult.OK) 
       folderName = browse.SelectedPath; 

      return folderName; 
     } 

     // Return whatever value if it wasn't a string - Should never occur! 
     return value; 
    } 

    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) 
    { 
     return UITypeEditorEditStyle.Modal; //base.GetEditStyle(context); 
    } 

    public class BrowseForFolderAttribute : Attribute 
    { 
     public BrowseForFolderAttribute(string description) 
     { 
      this.Description = description; 
     } 

     public string Description { get; set; } 
    } 
} 

그리고 내 Activity의 코드를 선언하는 방법이 있습니다 : 그것은 어떤 차이가 있는지

[Description("Select the folder where the files will be 
    copied/moved to.")] 
    [Category("Folders")] 
    [Browsable(true)] 
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] 
    [BrowseForFolderEditor.BrowseForFolder("Select the folder where the files will be 
    copied/moved to.")] 
    [Editor(typeof(BrowseForFolderEditor), typeof(UITypeEditor))] 
    public string TargetPath { get; set; } 

모르겠어요하지만 내 워크 플로우 Activity 유형은 NativeActivity입니다.

속성은 속성 표에 나타나지만 줄임표 단추가없는 텍스트 상자로 표시됩니다.

도움을 주시면 감사하겠습니다.

UPDATE-1 :

문제는 난 그냥 CodeActivity에 내 코드를 변경했습니다과는 차이를하지으로 NativeCodeActivity 사실과는 아무 상관이 없습니다.

답변

1

나는 즉 Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4

어쨌든,이 정보를 기반으로, 나는 ('...') 텍스트 상자와 툴팁을 줄임표 단추를 표시하는 관리 Microsoft에서 제공하는 몇 가지 샘플을보고 그것을 알아 냈다 텍스트 상자가 너무 짧아 경로를 표시 할 수없는 이벤트입니다. 그것은 단지 'BrowseForFolder'대화 상자의 다른 속성을 설정하기 위해 추가 속성을 추가하는 방법을 찾는 것처럼 완벽하지는 않지만 내 결과를 공유 할 것이라고 생각했습니다. 내 편집기로 정의

은 다음과 같습니다

public class BrowseForFolderEditor : DialogPropertyValueEditor 
{ 
    public BrowseForFolderEditor() 
    { 
     // Create a textbox, a '...' button and a tooltip. 
     string template = @" 
      <DataTemplate 
       xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
       xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' 
       xmlns:pe='clr-namespace:System.Activities.Presentation.PropertyEditing;assembly=System.Activities.Presentation'> 
       <DockPanel LastChildFill='True'> 
        <pe:EditModeSwitchButton TargetEditMode='Dialog' Name='EditButton' DockPanel.Dock='Right'>...</pe:EditModeSwitchButton> 
        <TextBlock Text='{Binding Value}' Margin='2,0,0,0' VerticalAlignment='Center'> 
         <TextBox.ToolTip> 
          <ToolTip> 
           <TextBlock Text='{Binding Value}' Margin='2' VerticalAlignment='Center' HorizontalAlignment='Left'/> 
          </ToolTip> 
         </TextBox.ToolTip> 
        </TextBlock> 
       </DockPanel> 
      </DataTemplate>"; 

     using (var sr = new MemoryStream(Encoding.UTF8.GetBytes(template))) 
     { 
      this.InlineEditorTemplate = XamlReader.Load(sr) as DataTemplate; 
     } 
    } 

    public override void ShowDialog(PropertyValue propertyValue, 
     IInputElement commandSource) 
    { 
     var browse = new FolderBrowserDialog 
     { 
      ShowNewFolderButton = true, 
      SelectedPath = propertyValue.StringValue, 
      Description = "Select Target Folder:", 
      RootFolder = Environment.SpecialFolder.MyComputer 
     }; 

     if (browse.ShowDialog() == DialogResult.OK) 
     { 
      propertyValue.Value = browse.SelectedPath; 
     } 

     browse.Dispose(); 
    } 
} 

나는 XAML에 대해 너무 많은 세부 사항으로받지 않습니다,하지만 몇 가지주의 사항을 다음 InlineEditorTemplate가, 즉 설정 방법

  1. 을 문자열에 미리 정의 된 XAML로 설정하면됩니다.
  2. Activity 생성자에 포함 된 사용자들은 도구 설명, 즉 가치

'중요한'코드의 텍스트 상자 즉 가치

  • 바인딩의 바인딩 경우 :있는 TargetPath 문자열 속성을 나타냅니다

    AttributeTableBuilder builder = new AttributeTableBuilder(); 
    
    builder.AddCustomAttributes(typeof(CopyMoveFiles), "TargetPath", 
          new EditorAttribute(
          typeof(BrowseForFolderEditor), 
          typeof(DialogPropertyValueEditor))); 
    
    MetadataStore.AddAttributeTable(builder.CreateTable()); 
    

    PropertyGrid에 표시됩니다.

    확실히 개선의 여지가 있지만 시작일뿐입니다. 언급 할 가치가있는 한 가지는 다양한 참조를 추가하는 것이 고통이었습니다. 나는 이것에 더 이상 시간을 낭비 할 여유가 없지만 Microsoft 프로젝트에 따라 모든 참조를 추가 한 후에도 여전히 작동하지 않을 것이고 결국 그렇게했습니다. 그래서 아직도 왜 이런 일이 부끄러운 것인지 잘 모르겠습니다. 그러나 누군가가 그것을 시도하고 어느 기준이 그들에게 문제를 주는지 정확히 지적 할 수 있다면, 나는 알고 싶어 할 것입니다.

    희망이 도움이됩니다.

    업데이트 : 생성자에서 프로그래밍 방식으로 속성을 정의하지 않으려면

    , 당신은 간단하게 사용할 수있는 속성 :

    [Editor(typeof(BrowseForFolderEditor), typeof(DialogPropertyValueEditor))] 
    public string TargetPath { get; set; }