What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 14338 |  Welcome, Guest!   Register  Login
Home > Articles > WWF > Workflow Foundation 4.0 - PropertyValueEditor

Workflow Foundation 4.0 - PropertyValueEditor

1 vote(s)
Rating: 5 out of 5
Article posted by Ambily.raj on 1/10/2011 | Views: 7962 | Category: WWF | Level: Beginner | Points: 250 red flag


Workflow Foundation 4.0 has very good support for custom activity development. We can have our own custom activity with very good look and feel. When you define a custom activity, one of the main requirements is how to manage the associated properties in the property grid.

We can either use the TypeConverter or PropertyValueEditor for managing the properties and associated editors in PropertyGrid. TypeConverters are same as those in WPF. PropertyValueEditors are similar to the PropertyEditors in WPF, which provides custom editor for our property. In this article we will discuss about the PropertyValueEditor.

PropertyValueEditor

WF4.0 contains mainly three types of editors defined under System.Activities.Presentation.PropertyEditing namespace. 

  1. PropertyValueEditor 
  2. DialogPropertyValueEditor 
  3. ExtendedPropertyValueEditor

For our sample and understanding, I am using the DialogPropertyValueEditor with Simple implementation. In another article we will look into how we can use the DialogPropertyValueEditor to show a dictionary of values and also will have a discussion on another type of editors.

Template

For defining any kind of Editors, we need one Template file which define the look and feel appear in the Propertygrid and the class file contains the editor logic.

For our sample, I am using the following template with one textbox and an EditModeSwitchButton. We can define the DataTemplate in a ResourceDictionary file or as part of a UserControl.

 

<DataTemplate x:Key="FileBrowserInlineEditorTemplate">

        <Grid>

            <Grid.ColumnDefinitions>

                <ColumnDefinition Width="1*"/>

                <ColumnDefinition Width="Auto"/>

            </Grid.ColumnDefinitions>

            <TextBox Grid.Column="0" Text="{Binding StringValue}"/>

            <PropertyEditing:EditModeSwitchButton Grid.Column="1"/>

        </Grid>

    </DataTemplate>


PropertyValueEditor

Next is the implementation of the Custom PropertValueEditor. Custom propertyValueEditor should be inherited from one of the above three classes.

In our sample, we are inheriting our Custom PropertyValueEditor from the DialogPropertyValueEditor class.  Specify the InlineEditorTemplate in the Constructor. In our example, FileEditorResources is the ResourceDictionary, where we defined the template for the PropertyValueEditor. Override the ShowDialog method and implement our custom PropertyValueEditor behavior.

In our example, we are using the OpenFileDialog to select an XML file.

class FileBrowserDialogPropertyValueEditor : System.Activities.Presentation.PropertyEditing.DialogPropertyValueEditor

    {

        private FileEditorResources res = new FileEditorResources();

 

        public FileBrowserDialogPropertyValueEditor()

        {

            this.InlineEditorTemplate = res["FileBrowserInlineEditorTemplate"] as DataTemplate;

        }

 

        public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)

        {

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "XML files (*.xml)|*.xml";

            ofd.Title = "Select XML file";

            ofd.Multiselect = false;

 

            if (ofd.ShowDialog() == true)

            {

                propertyValue.StringValue = ofd.FileName;

            }

        }

    }


Test Activity

Let us use our Custom PropertyValueEditor in our Custom Activity. Attach the Editor attribute with the custom activity property. 
 

public class TestActivity:CodeActivity

    {

        private string myFile;

               

        [Browsable(true)]

        [Editor(typeof(FileBrowserDialogPropertyValueEditor), typeof(DialogPropertyValueEditor))]

        public string MyFile

        {

            get

            {

                return myFile;

            }

            set

            {

                myFile = value;

            }

 

        }

 

        protected override void Execute(CodeActivityContext context)

        {

            MessageBox.Show(MyFile);

        }

    }

Result


Drag and drop the custom activity to workflow and observe the properties associated with it.  Our MyFile property will appear with a textbox & Selection button. Once we click on the button, it will open the File Open dialog with title as Select XML file and filtered by XML files.


 

Conclusion

Window workflow foundation 4.0 is having full support for custom activity development. In custom activity development, we are dealing with various kinds of properties. A good Property value editor will increase the user friendliness of the custom activity. Here, we discussed about a simple custom property value editor. We will look more on the editors and type converters in another article.
 
 

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About Ambily KK

Experience:9 year(s)
Home page:http://ambilykk.com/
Member since:Tuesday, May 18, 2010
Level:Silver
Status: [Member] [Microsoft_MVP] [MVP]
Biography:I have over 9 years of experience working on Microsoft Technologies. I am carrying the passion on Microsoft technologies specifically on web technologies such as ASP .Net and Ajax. My interests also include Office Open XML, Azure, Visual Studio 2010. Technology adoption and learning is my key strength and technology sharing is my passion.
>> Write Response - Respond to this post and get points
Related Posts

Workflow Foundation 4.0 is introduced a significant amount of change from the previous versions of the technology. In WF4.0, we are using Extensions for communication between the host and workflow, the workflow and its child activities and between child activities. There are two types of extensions in WF4.0, in this article we will look into the normal extensions.

Workflow Foundation 4.0 is introduced a significant amount of change from the previous versions of the technology. This article will be the third in a series of articles. In this article we will be discussing about how to pass data from host application to workflow without using bookmarks.

Workflow Foundation 4.0 is integrated with WCF and WPF. WF 4.0 uses WPF for activity designers and gives a very good support for custom activity designers with full WPF functionality. In this article we will look into the WCF integration to WF4.0.

One of the major changes in Windows Workflow Foundation 4.0 is the Activity Designer. The new Activity Designer is based on WPF.

Workflow Foundation 4.0 is introduced a significant amount of change from the previous versions of the technology. This article will be the first in a series of articles. In this article I will be discussing about the introduction to Custom Activity Development. In next articles, I will be concentrating more on the different aspects of Custom Activity Development.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 6:07:57 PM