Switch from VB to C# in Workflow Designer - visual-studio

I'm creating an Activity Library in Visual Studio 11 Beta (although I've repeated all my steps in VS2010 with the same result), targeting the .NET 4.0 framework.
As I started entering arguments via the Workflow Designer, I noticed the "Enter a VB Expression" message in the Default Value box. I'm not sure how to change the language context from VB to C#.
To create the project, I followed these steps:
Go to File> New and select Project...
In the Installed> Templates section of the New Project dialog window, select Visual C#> Workflow> Activity Library
Name the project, as usual, and click OK
And that's basically it. I noticed then that the default Activity1.xaml file was expecting VB in the default values fields. I deleted it and then followed these steps to create a new Activity:
Right-click on the project and select Add> New Item...
In the Add New Item dialog window, navigate to Installed> Visual C# Items> Workflow> Activity
Name the Activity and click OK
It was the same result, the Default Value fields are expecting a VB expression.
When I look at the XAML code, I can clearly see the Microsoft.VisualBasic.Activities namespace listed and a VisualBasic.Settings element, but I'm not sure what to do to change it; everytime I try, I just end up screwing things up. Here's the XAML code being generated:
<Activity mc:Ignorable="sads sap" x:Class="THINKImport.CustomerAddOrderAdd"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:local="clr-namespace:THINKImport.THINKWebReference"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
xmlns:s="clr-namespace:System;assembly=System.Core"
xmlns:s1="clr-namespace:System;assembly=System"
xmlns:s2="clr-namespace:System;assembly=System.ServiceModel"
xmlns:s3="clr-namespace:System;assembly=mscorlib"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:t="clr-namespace:THINKImport"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Members>
<x:Property Name="user_login_data" Type="InArgument(local:user_login_data)" />
<!--Removed the other properties for brevity-->
</x:Members>
<sap:VirtualizedContainerService.HintSize>440,440</sap:VirtualizedContainerService.HintSize>
<mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings>
</Activity>

I was able to figure out the issue.
First, though, I was able to discover the root cause here. In a nutshell, it says VB.NET must be used in the Expression Editor even if the program is in C#.
So, I was kinda bummed about that, but I decided to take another crack at the XAML code because, in working through the WF tutorials, there was most definitely an activity I was working on in the designer that would accept Expressions in C#. I opened up that project and went through the XAML code.
It's then that I noticed this line:
<sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>
I searched the MSDN library and found the documentation for the ExpressionActivityEditor class. As best as I can tell, this is new to .NET 4.5. In my particular case, there isn't any reason I can't target .NET 4.5 in my project, so I changed it. Once the solution reopened, right away, all the Expression Editor text fields and boxes would accept C#. In order to "start fresh", I deleted the activity file I had been working on and created a new one. If anyone's interested, here's that generated XAML code:
<Activity mc:Ignorable="sap sap2010 sads" x:Class="THINKImport.CustomerAddOrderAdd"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:THINKWebReference="clr-namespace:THINKImport.THINKWebReference">
<x:Members>
<x:Property Name="user_login_data" Type="InArgument(THINKWebReference:user_login_data)">
<x:Property.Attributes>
<RequiredArgumentAttribute />
</x:Property.Attributes>
</x:Property>
<x:Property Name="customer_data" Type="InArgument(THINKWebReference:customer_data)" />
<!--Remainder of Properties removed for brevity-->
</x:Members>
<sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>
<TextExpression.NamespacesForImplementation>
<sco:Collection x:TypeArguments="x:String">
<x:String>System</x:String>
<x:String>System.Collections.Generic</x:String>
<x:String>System.Data</x:String>
<x:String>System.Linq</x:String>
<x:String>System.Text</x:String>
</sco:Collection>
</TextExpression.NamespacesForImplementation>
<TextExpression.ReferencesForImplementation>
<sco:Collection x:TypeArguments="AssemblyReference">
<AssemblyReference>mscorlib</AssemblyReference>
<AssemblyReference>System</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
<AssemblyReference>System.Data</AssemblyReference>
<AssemblyReference>System.ServiceModel</AssemblyReference>
<AssemblyReference>System.Xml</AssemblyReference>
</sco:Collection>
</TextExpression.ReferencesForImplementation>
<sap2010:WorkflowViewState.IdRef>
THINKImport.CustomerAddOrderAdd_1
</sap2010:WorkflowViewState.IdRef>
<sap2010:WorkflowViewState.ViewStateManager>
<sap2010:ViewStateManager>
<sap2010:ViewStateData Id="THINKImport.CustomerAddOrderAdd_1" sap:VirtualizedContainerService.HintSize="440,440" />
</sap2010:ViewStateManager>
</sap2010:WorkflowViewState.ViewStateManager>
</Activity>
So, quite a bit different (to me, anyways) but I can use C# now, so I'm happy.

C# Expressions
Previously, all expressions in workflows can only be written in Visual
Basic. In .NET Framework 4.5 RC, Visual Basic expressions are only
used for projects created using Visual Basic. Visual C# projects now
use C# for expressions. A fully functional C# expression editor is
provided which capabilities such as grammar highlighting and
intellisense. C# workflow projects created in previous versions that
use Visual Basic expressions will continue to work.
As of Beta 1, C# expressions are validated at design-time. Errors in
C# expressions will be marked with a red wavy underline.
More: What's New in Windows Workflow Foundation in .NET 4.5

Related

Make IntelliSense work in Visual Studio

I am using Visual Studio 2015, and I want to add https://appsforoffice.microsoft.com/lib/1/hosted/office.js as an IntelliSense reference. So I did the following:
But the IntelliSense still does not work:
Could anyone help?
Getting the basics of JavaScript IntelliSense working is pretty straightforward – all you need to do is, in your JavaScript file, have a triple slash reference to the CDN location, as follows:
/// <reference path="
https://appsforoffice.microsoft.com/lib/1/hosted/office.js" />
In projects created with the Office Add ins template, the reference is already built in, in the Scripts/_reference.js file. The Scripts/_references.js file is a special file that acts as a "global" JS reference for the project, so that you don't need to include the /// <reference path="..." /> on every file. For more information on the _references.js file, see this excellent blog post by Mads Kristensen, creator of the “Visual Studio Web Essentials” extension: http://madskristensen.net/post/the-story-behind-_referencesjs.
Note that the above location is for the “prod” version of the CDN. For the beta endpoint, use "https://appsforoffice.microsoft.com/lib/beta/hosted/office.js", and for a local installation of Office.js point to the Office.js file (typically under "Scripts/Office/1/office.js).
TIP: Every once in a while, I've come across cases when the IntelliSense file appears stale. For example, while I know for a fact that the Excel Range object contains a “.merge()” method, IntelliSense was refusing to show it to me one day.
In these cases, you can refresh the JavaScript references by via the menu, by going to Edit -> IntelliSense -> Refresh Remote References, or via the VS Quick Launch box.

Multi-targeted WP7.1/WP8 app with Windows Phone Toolkit (Panorama / LongListSelector)

Was wondering if someone had a good idea of how to handle this.
In WP7.1, we can utilize the excellent Windows Phone Toolkit to include some useful controls such as LongListSelector and Panorama. These are part of the Microsoft.Phone.Controls.Toolkit assembly.
In WP8, we do not need the toolkit for those two controls because they're part of the official Microsoft.Phone.Controls assembly.
I have multi-targeted my app so that I have two phone projects, WP71 and WP80, where I link files in WP80 to files in WP71.
This works great until I try to use the Panorama or LongListSelector control in a XAML page. In the WP80 project, if I reference the WP80 DLL of the phone toolkit, it does not include the two aforementioned controls because, surprise, they're already present.
The issue is, WP71 needs the namespace declaration at the top of the XAML and the namespace is different for both projects.
WP71:
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
<toolkit:Panorama />
WP80:
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
<phone:Panorama />
I cannot build the projects because each project thinks the namespace is incorrect if I just use one because they need to point to different assemblies.
I don't think I can use compile constants in my XAML, otherwise that would be a fix.
My workaround was originally to just reference the older WP71 DLL in my WP80 project. But other 3rd party libraries bind against the official 8.0 SDK DLL (Caliburn, in my case) so it causes problems.
How can I solve this pickle? The only idea off the top of my head was to resort to code-behind to create the instance of the control :( Is there a better way?
Don't use a link, create a separate view for each.
Another solution might be to create a PanoramaEx control in each of the relative projects and inherit from Panorama. Then the view would reference the PanoramaEx control and you could still use a link to a single view. That's if both UI projects have the same namespace.
Edit: isn't panorama for WP7 in the namespace:
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
I do use my initial solution for ProgressBar and PerformanceProgressBar, I have a ProgressBarEx in each UI project, the WP7 one inherits from ProgressBar and the WP8 one inherits from PerformanceProgressBar and then in the views I reference ProgressBarEx.
Might not be the most elegant solution, but you can try to use a T4 file (.tt file) to generate both targets.
<## template language="C#" hostspecific="true"#>
<## output extension=".xaml"#>
<## assembly name="EnvDTE" #>
<phone:PhoneApplicationPage
x:Class="PhoneAppDemo.Pages.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
<# IServiceProvider serviceProvider = (IServiceProvider)Host;
EnvDTE.DTE dte = (EnvDTE.DTE)serviceProvider.GetService(typeof(EnvDTE.DTE));
var configName = dte.Solution.SolutionBuild.ActiveConfiguration.Name;
if (configName == "WP7") { #>
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
<# }else{ #>
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
<# } #>
>
<# include file="Page.xaml" #>
</phone:PhoneApplicationPage>
In this example, the inner content of the Page is in "Page.xaml". We just encapsulate it in <phone:PhoneApplicationPage> at processor time, based on the target name (usually Debug and Release, but in this example we assumed there was a target WP7).
For other stuff related to a multi-targeted silverlight app, you can always read Maintaining a WP7 and WP8 version of a same Silverlight application.

How to Migrate WP7 App to Windows 8 Metro style app

I want to migrate my Windows Phone 7 App, to a Windows 8.
I started doing it after this Documentation: http://msdn.microsoft.com/en-us/library/windows/apps/hh465136.aspx
Those are the steps:
Launch Microsoft Visual Studio Express 2012 RC for Windows 8 and create a new Metro style app using C++, C#, or Visual Basic. Choose a project template that best matches your app layout and functionality. For more info, see Jumpstart your Metro style app using templates (C#, C++, Visual Basic).
Copy the folders, code, and asset files that you want to reuse in the new project.
In the Visual Studio Solution Explorer, click Show All Files.
Select the files and folders that you copied, and then right-click them and select Include In Project.
Perform a global search and replace to replace "System.Windows" with "Windows.UI.Xaml".
Copy the reusable parts of your original XAML code into the new project's XAML files, or into newly created XAML files as necessary. You can often copy and reuse the contents of page layout roots (typically Grid elements), but not the outermost elements (typically PhoneApplicationPage elements).
My Question starts at point 2: Let's say i have a page: Settings.xaml and Settings.cs. Do i have to copy both of them or none and add the code later? If I add Settings.xaml i get an error because of the tag:
<phone:PhoneApplicationPage ...>
like it says at point 6.
I dont have any Problems with my dll's or with my "normal" classes, which arent connected to a xaml.
And when i create a Windows 8 Page i don't know where to add my Code from WP7 in Windows 8
<Grid Background="Transparent">
.....Code.....
</Grid>
I hope you guys can help me out.
I agree with ColinE, instead of copying over all the files directly, create a new Windows 8 project and copy the appropriate XAML elements and C#. If you've created separate supporting .cs files, those should copy over fine, but if your code is all together in a file, you need to figure out what methods to copy over and where to put them.
In terms of what kind of app to use (empty, grid, split, etc.) that depends on your application and its purpose. Take a look at the Designing UX for Apps article to help figure out what will work best for your app: http://msdn.microsoft.com/en-us/library/windows/apps/hh779072.
Here is another MSDN article that talks about porting a Windows Phone 7 app to a Windows 8 Metro app: http://msdn.microsoft.com/en-us/library/windows/apps/hh465136.aspx
Hope that helps!
Probably the easiest approach to tackling your XAML files is to create new usercontrols / pages in your Win8 project using Visual Studio. You can then cut and paste the XAML from WP7 to Win8 piece by piece. You can also copy across the code-behind during this process.
There are a few too many changes to make it possible to copy the XAML / cs files across directly.

adding visual studio XAML Intellisense to non-wpf classes

I have "DOM like" data structure in c# (parent, childNodes, properties, enums...) and I want to use xml\xaml file to some of the initializing. I already wrote a tool that transform my xaml to c# and inject them in the right place.
I want the exact Intellisense behavior of WPF except that my classes doesn't inherits from WPF base classes and my project in not wpf application on library and doesn't reference wpf assemblies. i also don't want to use xsd schema because classes are added and edited very frequently.
I'm using visual studio 2010
Is it possible?
Create a xaml (start by creating a resource dictionary and delete the content).
Add your own assembly as the default namespace and start using your types. I have created a test for sample data recently, here's how it looks like:
<MainViewModel xmlns="clr-namespace:MvvmTest.ViewModels.DesignTime"
Name="The design time main view model">
<MainViewModel.SubViewModels>
<FirstSubViewModel Name="The design time first sub-view model" />
<SecondSubViewModel Name="The design time second sub-view model" />
</MainViewModel.SubViewModels>
</MainViewModel>
You can load the file using the XamlReader class. As a bonus compared to xml, the file will be compiled and run time loading will be much faster.

How to apply the Classic theme on my WPF4 form?

We are currently migrating our app from VB6 to Net. As the Net forms will be in the minority we want them to blend in as good as possible with the VB6 forms. I thought that forcibly applying the Classic theme would accomplish this. This should be easy but I can't find how to do it. The examples provided target the Aero theme or Net3 which seems to have differently named referenced assemblies.
There are two ways to accomplish this:
Reference the classic.xaml file that is embedded in the Framework:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Classic;component/themes/classic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
`
Download the extracted classic.xaml file from here
This file holds a reference to the PresentationUI.dll which does not seem to be part of Net 4 framework. There is just one quixotic Control using this reference, so when you remove the reference and the control you are set to go!
More info here

Resources