Hi,
Let's see if I can help here.
When working in Blend (outside Unity) classes from Noesis are not used, the WPF framework is used instead. So there is no need to include any Noesis assembly reference. That is the reason why you have to use the preprocessor directives at the top of each .cs file, to be able to apply different code depending on whether the file is compiled in Blend for WPF, or in Unity/Visual Studio for Noesis.
If you want to be able to use Blend to design the xamls and share the same code-behind files with Unity, you should follow the next steps:
- Create a WPF application project in Blend. This will create .sln and .csproj files that are only valid for Blend, not Unity. As I said before there is no need to add any reference to a Noesis assembly.
- Inside Blend, add to the project a folder named Assets. Open Unity and click "OPEN" on the start screen to select that Assets folder as root of your Unity project.
- Every time you want to add content (UserControls, code classes, images, fonts...) to your Unity project you should do it from Blend.
For example, imagine you want to create a new UserControl, then:
- Go to Blend, right click the Assets folder selecting "Add new item...", and choose UserControl writing the name of the class (TestControl for example).
- This will add two files to your Blend project: TestControl.xaml and TestControl.xaml.cs.
- Open TestControl.xaml.cs and add at the very top of the file the following:
#if UNITY_5
#define NOESIS
#endif
#if NOESIS
using Noesis;
using System;
using System.Collections;
//add here namespaces required when compiling in Unity
#else
using System;
using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
//add here namespaces required when compiling in Blend
#endif
- Whenever there is a part of code that differs between WPF and Noesis use the NOESIS preprocessor directive to write the appropriate code in each case. For example, in Noesis you have to specify the xaml associated with the UserControl using an attribute. If you created it inside Assets/TestControl.xaml, then add the following:
#if NOESIS
[UserControlSource("Assets/TestControl.xaml")]
#endif
public class TestControl: UserControl
{
//...
}
If you want to try how your UserControl looks in Blend you just need to right click TestControl.xaml on the project to set it as the "Startup" file and "Run Project" (F5 key).
You can then go to Unity, create a new scene adding a NoesisGUIPanel component to the Main Camera and assign the TestControl.xaml to its Xaml property. You should be able to click "Play" and see the UserControl created in Blend in the Unity Game view. Double clicking the TestControl.xaml.cs file from Unity will open in Visual Studio the Unity .csproj (different from Blend) and it will allow you to debug the scripts as you play in Unity.
I hope this will help you understand how to use the power of Blend to design your xaml files while working in Unity.
Regards,
-Sergio