User avatar
Gazoo
Topic Author
Posts: 30
Joined: 14 Sep 2022, 10:00
Contact:

Using blend (view designer) with xaml files in Visual Studio

22 Sep 2022, 06:34

Hey yall,

A rookie question about using xaml and blend in Visual Studio. I've included a xaml file which I load into NoesisGUI and display. I'd now like to manipulate this via blend, but Visual Studio does not appear to let me access the 'designer' with this xaml file alone. I.e. I try to right click on it in the solution explorer and just get to edit code. Same if I open the solution directly in Blend.

My limited understanding is that a CSharp project is needed to properly manipulate xaml via Blend?

(Here's a resource for readers to pursue which I'm going to, if needed: https://stackoverflow.com/questions/207 ... sing-cmake)

If this is true, I'm somewhat confused as to why, as I would have thought no C# gets if/when the xaml is loaded into NoesisGUI?

Cheers,
Gazoo
 
User avatar
fllorens
Site Admin
Posts: 1
Joined: 01 Aug 2022, 09:32

Re: Using blend (view designer) with xaml files in Visual Studio

22 Sep 2022, 17:32

Hi Gazoo,

Yes, i't's a little confusing! You have to create a new project with Blend: use the WPF App .Net Framework template in the Project Creation screen.

Once you have created the project, simply move or copy your xamls and assets to the Project folder.

Now go to Blend > Solution Explorer (located on the left) and search for your xaml, double-click it and you should be able to edit it visually no problem.

Lastly, install 'Noesis.GUI.Extensions' Nuget via 'Tools > NuGet Package Manager > Manage NuGet Packages' to use Noesis Extensions with Blend.

Have a nice time designing!
 
User avatar
Gazoo
Topic Author
Posts: 30
Joined: 14 Sep 2022, 10:00
Contact:

Re: Using blend (view designer) with xaml files in Visual Studio

23 Sep 2022, 07:31

Thanks for the reply fllorens.

I've managed to build an include a C# WPF project alongside my native C++ project. My understanding is that this is apparently required in order to access Blend/designer view when modifying the xaml file.

I have 2 follow-up questions.

1. The xaml file that I use to load natively in C++ is just a grid, like this:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="400">

    <Button x:Name="button" VerticalAlignment="Center" Content="Click me"/>

</Grid>
I've noticed that the WPF projects default xaml defines a window class in it:
<Window x:Class="Example.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Example"
        mc:Ignorable="d"
        Title="MainWindow" Height="800" Width="800">
    <Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

        <Button x:Name="button" Width="100" VerticalAlignment="Center" Content="Click me"/>

    </Grid>
</Window>
For fun, I tried to execute this in my native application and NoesisGUI threw an exception. Likely because I'm defining an unnecessary window (as my native app already has one). However, I'm wondering if there is a simple way to bridge the gap and have my GUI xaml that I expect to load in my native application, also load in the C# WPF application?

I looked into embedding xaml files from other xaml files and found limited help. I'm wondering if you have any ideas or suggestions about this approach?

One of the benefits I think might be exclusive to running in a C# app is proper hot-reloading.

2. My other question relates to clicking the button in the designer for my xaml file. If I do this enough, the designer crashes/throws an exception. It appears this has to do with the designer trying to find the C# back-end object connected to the widget I think, as that's the behavior I see if I click sufficiently on a button in the original application's xaml. Is there a recommended way of avoiding the designer crashing when inspecting objects in 'loose xaml' files, aside from just not clicking it too much?

Cheers,
Gazoo
 
User avatar
jsantos
Site Admin
Posts: 3548
Joined: 20 Jan 2012, 17:18
Contact:

Re: Using blend (view designer) with xaml files in Visual Studio

23 Sep 2022, 10:29

In our C++ SDK you can see how our examples are structured. For every example we have a project in C++ and another one in Blend (*-blend.sln) and both are sharing the same XAML files. So you can edit the XAML from the Blend project and the changes apply instantly to C++ (if you have the inspector tool this will work too with Hot-Reloading).

Please have a look about how we are using Window containers and things like that in our examples. Our App framework exposes a Window implementation.

Regarding embedding xaml files from other xaml files, you can use UserControls or LoadContentAction.

Are you able to crash the designer too in our examples?
 
User avatar
sfernandez
Site Admin
Posts: 2665
Joined: 22 Dec 2011, 19:20

Re: Using blend (view designer) with xaml files in Visual Studio

23 Sep 2022, 11:42

Just one clarification, in Blend you can use a Grid also as root of the xaml. So you can use the exact same xaml you have in your native application, just include it in Blend and set the StartupUri in the App.xaml to point to that xaml file.
 
User avatar
Gazoo
Topic Author
Posts: 30
Joined: 14 Sep 2022, 10:00
Contact:

Re: Using blend (view designer) with xaml files in Visual Studio

24 Sep 2022, 03:31

jsantos --

I appreciate you noting the NoesisGui example projects. I am diligently looking through them as best I can. I've succesfully gotten both a C# project and C++ project to share and edit the same .xaml file. I have not had any success hot-reloading a running C++ application and changing the xaml file, although I'm not sure this is supposed to be possible?

I acknowledge that the NoesisGui framework exposes a Window implementation. I'm using the LibCinder application framework and will primarily be using NoesisGui for Gui rendering only.

Yes - I can replicate the designer crash in the Noesis 'Integration-blend' project. Note, the Blend application as whole does *not* crash, but the designer window throws a System.NullReferenceException, if I click sufficiently many times on certain controls.

Despite my limited understanding, I'm fairly certain this is due to Blend expecting an underlying C# file to correspond to various xaml elements, which does not exist in the integration project. In other projects, clicking a sufficient number of times on certain controls will eventually lead the editor to open up a line in a C# file.

Happy to provide a step-by-step reproduction if you'd like, but I don't think it's a massive issue. More of an annoyance. Furthermore, it's not so much a NoesisGui problem, as it is a Blend problem. I suspect the developers behind Blend did not envision its use on xaml files with accomanying C# files.

sfernandez --

I appreciate the suggestion re. StartupUri - I will investigate this. Also appreciate your suggestion jsantos re the use of UserControls or LoadContentAction.
 
User avatar
Gazoo
Topic Author
Posts: 30
Joined: 14 Sep 2022, 10:00
Contact:

[Solved] Re: Using blend (view designer) with xaml files in Visual Studio

01 Oct 2022, 05:39

I'll assume there's no strong interest in replicating the null reference error in Blend, for now.

Thanks again for all the help so far.

Much appreciated,
Gazoo
 
User avatar
jsantos
Site Admin
Posts: 3548
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Solved] Re: Using blend (view designer) with xaml files in Visual Studio

01 Oct 2022, 13:42

I'll assume there's no strong interest in replicating the null reference error in Blend, for now.
I will try to reproduce the problem and will come back to you. Anyway, we are now working on a Blend replacement. More news, soon. :)
 
User avatar
Gazoo
Topic Author
Posts: 30
Joined: 14 Sep 2022, 10:00
Contact:

Re: Using blend (view designer) with xaml files in Visual Studio

02 Oct 2022, 01:42

Let me know if you'd like a step-by-step guide. Should be fairly straight-forward.

I'll emphasize again, it's not so much an actual problem, as an annoyance. It'd be preferable if Blend - when unable to find related C# code - would perhaps show a benign console warning, rather than replace the designer window with a null reference.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Semrush [Bot] and 3 guests