0

WF 4.5ワークフローアクティビティでフォルダの参照を実装しようとしていますが、省略記号ボタンが表示されず、ほとんど何も起こりません。Windows Workflow Designer 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

が提供するいくつかのサンプルを見て、それを考え出しましたテキストボックスが短すぎてパスを表示できないイベント。私は、「BrowseForFolder」ダイアログの他のプロパティを設定するために追加の属性を追加する方法を探していますが、完璧ではありませんが、私は自分の発見を共有すると思いました。

私の編集者は次のように定義されています。私はXAMLについてはあまり詳細に得ることはありません

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(); 
    } 
} 

が、注意すべきいくつかのこと:InlineEditorTemplateは、すなわち設定されている方法

  1. 文字列にあらかじめ定義されているXAMLに設定します。
  2. のTextBoxすなわち価値の結合
  3. ツールチップすなわち価値の結合

Activityコンストラクタに記載された「重要」のコードは次のとおりです。

TargetPathが、文字列プロパティを表し
AttributeTableBuilder builder = new AttributeTableBuilder(); 

builder.AddCustomAttributes(typeof(CopyMoveFiles), "TargetPath", 
      new EditorAttribute(
      typeof(BrowseForFolderEditor), 
      typeof(DialogPropertyValueEditor))); 

MetadataStore.AddAttributeTable(builder.CreateTable()); 

PropertyGridに表示されます。

明らかに改善の余地がありますが、これは始まりです。かなりうまくいくようです。言及する価値のあることの1つは、さまざまな参考文献を追加することは苦痛であったということです。私はもうこれ以上時間を無駄にすることはできませんが、Microsoftプロジェクトごとにすべての参照を追加しても、それはまだ機能しませんでした。だれかがそれを試して、どれが参考になったのかを突き止めることができれば、私は知りたいと思うだろう。

これが役に立ちます。

更新:

あなたは、コンストラクタでプログラムの属性を定義しない場合、あなたは、単に属性を使用することができます。

[Editor(typeof(BrowseForFolderEditor), typeof(DialogPropertyValueEditor))] 
public string TargetPath { get; set; } 
関連する問題