We will refactor the solution created in last post Hello Workflow . Even
though we have a working application, we might want to make a few
improvements. In this post, as Workflow1
is not a very descriptive name, you will change it to SayHello.
- To
change the name of the workflow defined in Workflow1.xaml,
Open it with the workflow designer
and click on an empty area the designer surface. This will allow us to change
the properties of the workflow.Click on an empty area of the designer surface so you can set the name of the workflow
- In
the Properties window, set the Name
property of the Workflow to HelloWorkflow.SayHello
(C#) or SayHello (VB).Set the Name property of the workflow (C#)Set the Name property of the workflow (VB)
- While
it is not required, it is a good idea for the name of the .xaml file to match
the name of the activity contained in it. In Solution Explorer, right-click Workflow1.xaml, select Rename and type SayHello.xaml.Watch OutWhen you rename C# or Visual Basic files, Visual Studio asks you if you want refactoring to change the name of the class also. It does not do this when renaming XAML files, so if you want to change the name of the workflow also you need to do this manually.
- Press CTRL+SHIFT+B to build the solution. It will fail to compile because you
changed the name of the workflow.The workflow fails to compile (C#)The workflow fails to compile (VB)
- Note : Why does the
application fail to compile when I change the workflow name?
Your workflow is actually a class declared in XAML that inherits from System.Activities.Activity. The name of the workflow is the name of the class that must be created to run the workflow. When you set the Name property, you changed the name of the class. - To fix the build break, open Program.cs (C#) or Module1.vb (VB) and modify it to use the new SayHello class name. To do this:a. Locate the WorkflowInvoker.Invoke method call.b. Modify it to use SayHello instead of Workflow1 as shown in the following code (shown in bold).C#static void Main(string[] args){WorkflowInvoker.Invoke(new SayHello());}Visual BasicShared Sub Main()WorkflowInvoker.Invoke(New SayHello())End SubNote: Why does Visual Studio warn me that the type SayHello is not defined?If you change Main() before compiling the workflow with the new SayHello name, you may notice a warning about the type SayHello not being defined. The reason for this is that Visual Studio is not aware of types declared in XAML until you build the solution.
- Press CTRL+SHIFT+B to build the solution. It should now build without errors.
- Press CTRL+F5 to
run it. You should see the same message as before “Hello Workflow 4"Hello Workflow 4 message
- If
you want to see the XAML, right click on the SayHello.xaml file and select View Code. Visual Studio will warn
you that the file is already open in the designerFile already opened in the designer warningJust click Yes to close the designer and you will see the workflow definition in XAML.XAML<Activity mc:Ignorable="sap"x:Class="SayHello"xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"...<WriteLine ... Text="Hello Workflow 4" /></Activity>
nice for helping others, keep it up :)
ReplyDelete