How do you load GUI XAML from a file?

Post Reply
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

How do you load GUI XAML from a file?

Post by IXix »

How do you load the XAML for a machine GUI from a file instead of embedding it in "machine.GUI.dll"?

I looked but I can't find a machine example. There's a "Jeskola Limiter.xaml" in my gear folder so I looked at the limiter code but it doesn't seem to use that file.
oskari
Site Admin
Posts: 296
Joined: Mon Nov 21, 2011 2:04 pm

Re: How do you load GUI XAML from a file?

Post by oskari »

Here's an example: http://svn.jeskola.net/buzzgui/BuzzGUI. ... troller.cs . The hack thing is needed to make it work in Program Files subdirs.
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: How do you load GUI XAML from a file?

Post by IXix »

oskari wrote:Here's an example: http://svn.jeskola.net/buzzgui/BuzzGUI. ... troller.cs . The hack thing is needed to make it work in Program Files subdirs.
Thanks! I think I understand it...
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: How do you load GUI XAML from a file?

Post by IXix »

IXix wrote:I think I understand it...
I was so wrong.

Code: Select all

<UserControl x:Class="GUI.PatchbayGUI"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:GUI"
             xmlns:xtextbox="clr-namespace:EditableTextBlockControl"
             xmlns:updown="clr-namespace:NumericUpDownControl"
             mc:Ignorable="d" 
             d:DesignHeight="500" d:DesignWidth="500" Name="GUI">
    <UserControl.Resources>
        <local:BooleanToVisConverter x:Key="_Converter"/>
First I got this exception...
Specified class name 'GUI.PatchbayGUI' doesn't match actual root instance type 'System.Windows.Controls.UserControl'. Remove the Class directive or provide an instance via XamlObjectWriterSettings.RootObjectInstance.
I couldn't find RootObjectInstance so I removed the class directive and tried again but then I got...
Cannot create unknown type '{clr-namespace:GUI}BooleanToVisConverter'.' Line number '12' and line position '10'."}
So basically I haven't got a clue what I'm doing. Sorry. Please could you explain a bit more?
oskari
Site Admin
Posts: 296
Joined: Mon Nov 21, 2011 2:04 pm

Re: How do you load GUI XAML from a file?

Post by oskari »

Add the name of the assembly (dll) in the namespace declaration, like in xmlns:bgc="clr-namespace:BuzzGUI.Common;assembly=BuzzGUI.Common"
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: How do you load GUI XAML from a file?

Post by IXix »

oskari wrote:Add the name of the assembly (dll) in the namespace declaration, like in xmlns:bgc="clr-namespace:BuzzGUI.Common;assembly=BuzzGUI.Common"
Thanks, that cures some of the problems and I think the remaining problems are similar so I'll try to work them out myself. I'll scream again if I get stuck. :)
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: How do you load GUI XAML from a file?

Post by IXix »

Oh, I have to hook ALL the events manually! Ouch, that's a lot of events to hook. :(

Do you think it could be possible to compile the UserControl into a separate dll and get my machine GUI to load that instead?

The problem I'm trying to work around is that I can't load multiple copies of the same GUI.dll with different filenames. The C++ machine determines its I/O config (and parameter count) from the filename so the user can rename copies to get different machine configurations. It works great but the gui.dll has to be renamed too, which works up to a point but then falls apart. If I create machine A, then machine B, then try to make another machine A it fails because (as far as I can tell) the resources initialised for machine A have been destroyed by the initialisation of machine B, I guess because they share the same assembly name.

I'm starting to think I should abandon the clever renaming system and just make a few fixed configurations but I'm loathe to admit defeat and scrap all the work I did to get it working.

I should just stick to drumming, it's much more fun. :roll:
mute
Posts: 417
Joined: Mon Nov 21, 2011 8:30 pm

Re: How do you load GUI XAML from a file?

Post by mute »

It's been a long time, but I want to say you don't have to create any additional hooks at all (unless you want to expand) when you use Usercontrols. IIRC when you create a Wpf Usercontrol it also will create all the basic methods/properties and xaml.. I would have to do some googling as a refresher but it sounds like you're making it harder on yourself than need be. Honestly, I'd just look around Codeplex for some recent examples.. I know theres a gotta be a ton.
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: How do you load GUI XAML from a file?

Post by IXix »

mute wrote:you don't have to create any additional hooks at all (unless you want to expand) when you use Usercontrols. IIRC when you create a Wpf Usercontrol it also will create all the basic methods/properties and xaml.
Not if you're loading the xaml at runtime. If the xaml is embedded in the assembly then the compiler hooks up all the events and stuff for you and it just works but if you load the xaml from a file at runtime you have to do that stuff yourself.

It's not super difficult but there's tons of it. :(
mute
Posts: 417
Joined: Mon Nov 21, 2011 8:30 pm

Re: How do you load GUI XAML from a file?

Post by mute »

hrmn.. but you can't you do something like 1) create user control / xaml file 2) add xaml file to project (still referencing local file) 3) goto toolbox, find your control, add it to the form - bingo, methods are there?

sorry for the back/forth.. more curious than anything. I know I've done things with controls like this somehow using files..its just been like 3-4 years..
User avatar
IXix
Posts: 1113
Joined: Wed Nov 23, 2011 3:24 pm

Re: How do you load GUI XAML from a file?

Post by IXix »

Not sure. The embedded xaml gets lost somewhere so I need to either generate it in code or load it from a file. Doing that means none of the compiler magic happens but if my loaded/generated xaml references a control from a previously compiled dll then that control should have its own magic, in which case I'd maybe only need to hook a couple of things up to make it work. I don't know. I'm guessing hard.

Here's the machine if you want to see what happens. The zip contains two renamed copies of the original effect dlls. Add a 12x4 and open the param window, do the same with a 16x8, then make another 12x4 and try to open the param window. It should throw an exception saying it can't find the xaml. The first two machines should still work properly.

IX PatchBay 3.0 Test.zip

If the assembly name was the same as the filename I wouldn't have this problem because the renamed gui.dlls would all have separate resources but they all have the same assembly name "IX PatchBay 3.0" so they clash somehow. Why loading a different copy of the gui.dll should break new instances of a previously loaded dll is beyond me but that's what happens. There must be a way to stop it but I'm a bit out of my depth.

The machine is stable but still has minor bugs. I wouldn't recommend using it for anything yet (although it's already better than PatchBay 2)
Post Reply