kguner
Topic Author
Posts: 17
Joined: 07 Apr 2015, 18:38
Contact:

Microsoft Blend for Visual Studio and Unity workflow

05 Nov 2015, 07:27

What is your current workflow when using the current version of Microsoft Blend for Visual Studio? The "Link to Existing Item..." option is no longer available.

The documentation here is using the old Microsoft Expression Blend 4 version.

I prefer coding my XAML but use the designer to see how it looks. The designer in Visual Studio gives me exceptions.


P.S. I pretty much read all forum posts and do not remember seeing anything about this, and I cannot perform a search because the search function complains about "blend" and "visual studio" being too common.
Last edited by kguner on 05 Nov 2015, 21:00, edited 1 time in total.

Tags:
 
Faerdan
Posts: 55
Joined: 02 Oct 2015, 09:11
Location: Galway, Ireland
Contact:

Re: Microsoft Blend for Visual Studio and Unity workflow

05 Nov 2015, 13:19

I just checked, and to link to a XAML file in the latest Visual Studio versions you must select "Add > Existing Item..."

See this screenshot:
Image

The Visual Studio project created by Unity (more specifically the UnityEngine library it references) is not compatible with the libraries which are required before you can visually edit XAML files in the designer.

In order to use the designer create a new "WPF Application" and add the XAML files (which should still be located within the Assets folder of your Unity project) there using "Add > Existing Item...". You can then view and edit these XAML files in the designer.

I hope that helps.
 
movra
Posts: 70
Joined: 02 Apr 2014, 20:35

Re: Microsoft Blend for Visual Studio and Unity workflow

05 Nov 2015, 15:17

Add Existing Item will copy the file if the file system folder structure doesn't match Blend's project folder structure. If the files are copies you're going to have a hard time syncing Unity with Blend. To prevent that you have to be careful how you set-up the projects.

For the folder structure there are several options:
  1. Create a new Blend project. Check "Create directory for solution". Create a folder named Assets under the project folder. Now you can open the project folder in Unity.

    The folder structure will look like this:

    SolutionName
    -- SolutionName.sln (created by Blend)
    -- WpfApplication1
    ---- WpfApplication1.sln (created by UnityVS)
    ---- Assets
    ------ MVVM
    -------- ViewModels
    -------- Views
  2. You could uncheck "Create directory for solution" to flatten the folder structure by one level, but then you have to rename the solution file that Blend created or it will be overwritten by Unity.

    WpfApplication1
    -- WpfApplication1Blend.sln (created by Blend, renamed by user)
    -- WpfApplication1.sln (created by UnityVS)
    -- Assets
    ---- MVVM
    ------ ViewModels
    ------ Views
  3. Create a new Unity project. Above the Assets folder start a new Blend project. Within the Assets folder put all your XAML stuff that belongs together in a single folder. Then create a symlink or junction from that folder to the Blend project folder.

    MyUnityProject
    -- Assets
    ---- MVVM
    ------- ViewModels
    ------- Views
    -- BlendMyUnityProject
    ---- MVVM (= Symlink/Junction to Assets/MVVM folder)
Adding files to the Blend project

When you have merged the Unity and Blend projects using one of the options above, you still have to avoid the Add Existing Item action.
  • You can add existing files to the Blend project file by revealing the folder structure by pressing the Show All Files button, selecting the files and executing the Include In Project context menu action.
  • When you create new files in Blend, you also have to be aware of the underlying hidden folder structure. Again, enable Show All Files and remember to be able open the files in Unity they have to be under the Assets folder.
Blend WPF & Noesis Compatibility

Now the UserControls that Blend creates are not directly compatible with Unity. In the other direction, Blend does not recognize Noesis classes out of the box.
  • You could create some dummy classes and store them in a separate reusable project
  • Use preprocessor directives (#if UNITY_5 ... #else ... #endif)
  • Create Blend templates that work with Noesis instead of using the default ones
 
kguner
Topic Author
Posts: 17
Joined: 07 Apr 2015, 18:38
Contact:

Re: Microsoft Blend for Visual Studio and Unity workflow

05 Nov 2015, 16:29

Great response Movra, thank you.
 
Faerdan
Posts: 55
Joined: 02 Oct 2015, 09:11
Location: Galway, Ireland
Contact:

Re: Microsoft Blend for Visual Studio and Unity workflow

05 Nov 2015, 17:18

Ah apologies, I did not realise that using Add Existing Item copied the file.

There is another solution which will allow you to link all of your XAML files without moving them.

Open the WPF project file (.csproj) in a text editor, and add the following ItemGroup entry:

<ItemGroup>
<None Include="Path\To\Your\XAML\**\*.xaml">
<Link>XAML\%(RecursiveDir)%(FileName)%(Extension)</Link>
</None>
</ItemGroup>

Each time you load the project it will automatically link all XAML files found in the Path\To\Your\XAML\ directory. This is the method I use.
 
kguner
Topic Author
Posts: 17
Joined: 07 Apr 2015, 18:38
Contact:

Re: Microsoft Blend for Visual Studio and Unity workflow

05 Nov 2015, 20:49

Faerdan,

Since it was possible in the project file I went to look about writing an extension for this. It turns out the functionality already does (still) exist.

After clicking "Add -> Existing Item..." the "Add" button is actually a dropdown and you can select "Add As Link".

Image

This is available in both Visual Studio and Blend.

Thank you both.
 
movra
Posts: 70
Joined: 02 Apr 2014, 20:35

Re: Microsoft Blend for Visual Studio and Unity workflow

06 Nov 2015, 01:16

D'oh! If you didn't tell me I'd probably never found out.

If you link a XAML together with a code-behind they don't get stacked as usual when you create a UserControl. You can edit the .csproj to add <DependentUpon>UserControl1.xaml</DependentUpon>, but it's kinda sloppy it doesn't do that automatically. Or maybe I overlooked a feature again.
 
kguner
Topic Author
Posts: 17
Joined: 07 Apr 2015, 18:38
Contact:

Re: Microsoft Blend for Visual Studio and Unity workflow

06 Nov 2015, 04:36

If you link a XAML together with a code-behind they don't get stacked as usual when you create a UserControl. You can edit the .csproj to add <DependentUpon>UserControl1.xaml</DependentUpon>, but it's kinda sloppy it doesn't do that automatically. Or maybe I overlooked a feature again.
Hmm, it did for me. I created the wpf project from Visual Studio and linked to both files (.xaml and .xaml.cs) and they automatically "stacked" and when i open the project in Blend it is the same there. I haven't tried linking inside Blend yet. Which did you try?
 
movra
Posts: 70
Joined: 02 Apr 2014, 20:35

Re: Microsoft Blend for Visual Studio and Unity workflow

06 Nov 2015, 09:27

Oh I see, you have to add only the .xaml and Blend/VS will include any matching.xaml.cs automatically. I selected both the .xaml and the .xaml.cs in the dialog.
 
User avatar
sfernandez
Site Admin
Posts: 1975
Joined: 22 Dec 2011, 19:20

Re: Microsoft Blend for Visual Studio and Unity workflow

06 Nov 2015, 10:52

First of all, a great thank you to movra for the extensive and precise answer, I think it covers almost all the options available to work with Blend/VS and Unity ;)

In our case, as you can see in the samples we are uploading to the Github, we follow the first option exposed by movra: create a Blend project and the directory structure there (BlendProject/Assets/...). As Blend does not allow you to add existing folders to the project, all the files and directories are always created from Blend. And then you can open the Unity project by selecting the BlendProject directory.

Who is online

Users browsing this forum: No registered users and 4 guests