Great forum, but not much going on...
-
Now, let me change that or send me to the Hall of Shame as well :) This here[^] is a little pet project of mine. Occasionally I have posted about it in the Lounge, but this looks like a better place to do that. The screenshot is not from the actual game. It's just the test application for the 3D engine and the GUI. I'm still adding controls or features to the 3D engine until I have enough to start on the game client. And please don't say anything abozt the 3D models. I had to make them myself. It's getting better, but I'm no big artist. At the moment I have hit an obstacle in the GUI. The layout can be loaded from XAML. This works well for serializable objects. The problem is, that the control's events are not serializable. At the moment the events are plain CLR events, using delegates and event handlers, just like in windows forms. They are not serialized into XAML and therefore can't be loaded from XAML. What I need now is a good and practicable idea th wrap the functionality of events into serializable classes.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011 ---
I am endeavoring, Madam, to construct a mnemonic memory circuit using stone knives and bearskins - Mr. Spock 1935 and me 2011 -
Now, let me change that or send me to the Hall of Shame as well :) This here[^] is a little pet project of mine. Occasionally I have posted about it in the Lounge, but this looks like a better place to do that. The screenshot is not from the actual game. It's just the test application for the 3D engine and the GUI. I'm still adding controls or features to the 3D engine until I have enough to start on the game client. And please don't say anything abozt the 3D models. I had to make them myself. It's getting better, but I'm no big artist. At the moment I have hit an obstacle in the GUI. The layout can be loaded from XAML. This works well for serializable objects. The problem is, that the control's events are not serializable. At the moment the events are plain CLR events, using delegates and event handlers, just like in windows forms. They are not serialized into XAML and therefore can't be loaded from XAML. What I need now is a good and practicable idea th wrap the functionality of events into serializable classes.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011 ---
I am endeavoring, Madam, to construct a mnemonic memory circuit using stone knives and bearskins - Mr. Spock 1935 and me 2011Why would you want to serialize events? And what exactly do you mean by "events"? Do you mean you want to serialize the code that is called when the event occurs? I have a few ideas, but I want to be sure I understand your problem fully first.
Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.
-
Why would you want to serialize events? And what exactly do you mean by "events"? Do you mean you want to serialize the code that is called when the event occurs? I have a few ideas, but I want to be sure I understand your problem fully first.
Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.
Perhaps I did not describe it well. We started out with ASP .Net pages, a browser game. That already worked well, but it was not really exciting. So we kept the code on the server side, but replaced the presentation part with a client. WPF would have provided all the GUI we would ever need, but we also wanted to be able to render 3D scenes to make the whole thing a bit more interesting. Making WPF work together with a 3D engine is not easy. You run into very many issues and you can never safely assume that it really works on every computer. So we ended up adding our own GUI to our XNA graphics engine. We carefully avoided all things which may not be available on the Windows Phone or the XBox, so the whole thing should also safely compile and run for those two. To be honest, we have not yet tested it, but at least in theory we are not limited to the PC. For all practical reasons the GUI works very much like Windows Forms. You have a Form object and can programmatically add controls or set their properties. Naturally we don't have a designer in Visual Studio because the whole thing is do it yourself. But we can live very well with designing our forms with XAML instead. That is not really hard to do since .Net 4.0 This works very much like XML serialisation and we simply can take a complete form with all its child controls and serialize it to XAML. When the XAML is deserialized again, we get a completely initialized instance of the form with all child controls, properties or even data items as they were before. It's actually only two lines of code, no more. You probably know how WinForm controls notify their parent forms of events, like buttons raising a OnClick event whenever the user clicks them. In the button's code the event would be declared like this:
public event EventHandler OnClick;
In the form you would find something like this:
Button.OnClick += new EventHandler(SomeMethodOfTheFormToHandleTheEvent);
Our GUI works exactly the same way. Plain ordinary delegates and event handler methods. The problem is, that the XAML does not contain anything about how the events of the controls and the event handlers are wired together. When we create a new instance of a form by loading the XAML, we get the complete form, but the information about which event handler method handles which control's events has been lost. Delegates and event handler methods are not serializable, so the only way to go is to replace them with something that is. It is possible, since WPF o
-
Now, let me change that or send me to the Hall of Shame as well :) This here[^] is a little pet project of mine. Occasionally I have posted about it in the Lounge, but this looks like a better place to do that. The screenshot is not from the actual game. It's just the test application for the 3D engine and the GUI. I'm still adding controls or features to the 3D engine until I have enough to start on the game client. And please don't say anything abozt the 3D models. I had to make them myself. It's getting better, but I'm no big artist. At the moment I have hit an obstacle in the GUI. The layout can be loaded from XAML. This works well for serializable objects. The problem is, that the control's events are not serializable. At the moment the events are plain CLR events, using delegates and event handlers, just like in windows forms. They are not serialized into XAML and therefore can't be loaded from XAML. What I need now is a good and practicable idea th wrap the functionality of events into serializable classes.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011 ---
I am endeavoring, Madam, to construct a mnemonic memory circuit using stone knives and bearskins - Mr. Spock 1935 and me 2011 -
Perhaps I did not describe it well. We started out with ASP .Net pages, a browser game. That already worked well, but it was not really exciting. So we kept the code on the server side, but replaced the presentation part with a client. WPF would have provided all the GUI we would ever need, but we also wanted to be able to render 3D scenes to make the whole thing a bit more interesting. Making WPF work together with a 3D engine is not easy. You run into very many issues and you can never safely assume that it really works on every computer. So we ended up adding our own GUI to our XNA graphics engine. We carefully avoided all things which may not be available on the Windows Phone or the XBox, so the whole thing should also safely compile and run for those two. To be honest, we have not yet tested it, but at least in theory we are not limited to the PC. For all practical reasons the GUI works very much like Windows Forms. You have a Form object and can programmatically add controls or set their properties. Naturally we don't have a designer in Visual Studio because the whole thing is do it yourself. But we can live very well with designing our forms with XAML instead. That is not really hard to do since .Net 4.0 This works very much like XML serialisation and we simply can take a complete form with all its child controls and serialize it to XAML. When the XAML is deserialized again, we get a completely initialized instance of the form with all child controls, properties or even data items as they were before. It's actually only two lines of code, no more. You probably know how WinForm controls notify their parent forms of events, like buttons raising a OnClick event whenever the user clicks them. In the button's code the event would be declared like this:
public event EventHandler OnClick;
In the form you would find something like this:
Button.OnClick += new EventHandler(SomeMethodOfTheFormToHandleTheEvent);
Our GUI works exactly the same way. Plain ordinary delegates and event handler methods. The problem is, that the XAML does not contain anything about how the events of the controls and the event handlers are wired together. When we create a new instance of a form by loading the XAML, we get the complete form, but the information about which event handler method handles which control's events has been lost. Delegates and event handler methods are not serializable, so the only way to go is to replace them with something that is. It is possible, since WPF o
CDP1802 wrote:
My first guess now is, that I must wire up the event after loading the form by finding the event handler method with reflection.
Yep, that'd probably be the way I'd go. As an alternative, you could give refer to the controls by their name. So, in your XAML you have this:
<Button
Name="MyButton"
Width="50"
Content="Click Me!" />Then in your C# code, you have this:
this.MainControl = SomeXamlHelper.LoadMyXaml(Config.XamlForThisClass);
Part of that
LoadMyXaml
method would load up all the sub-controls by theirName
. You could then refer to those controls by their name and wire up the handlers in the C#:(this.MainControl.FindControl("MyButton") as AwesomeButton).OnClick += new EventHandler(SomeMethodOfTheFormToHandleThisEvent);
Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.
-
CDP1802 wrote:
My first guess now is, that I must wire up the event after loading the form by finding the event handler method with reflection.
Yep, that'd probably be the way I'd go. As an alternative, you could give refer to the controls by their name. So, in your XAML you have this:
<Button
Name="MyButton"
Width="50"
Content="Click Me!" />Then in your C# code, you have this:
this.MainControl = SomeXamlHelper.LoadMyXaml(Config.XamlForThisClass);
Part of that
LoadMyXaml
method would load up all the sub-controls by theirName
. You could then refer to those controls by their name and wire up the handlers in the C#:(this.MainControl.FindControl("MyButton") as AwesomeButton).OnClick += new EventHandler(SomeMethodOfTheFormToHandleThisEvent);
Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.
Thanks. It's almost 4 AM now and time to go to bed. But now I have a plan which I can sleep over. Right now I again see two options: The form does further initialisation and layouting when it is attached to the UI after loading. That involves going through the form and all its children. This is a good place to also wire up all events and probably best suited for your approach. Or I might do it in a lazy fashion. When a control tries to raise an event and the wiring has not been done yet, then I may work my way back to the form, find the event handler method and wire it up on the fly. One way or the other, this was really helpful. Thanks.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011 ---
I am endeavoring, Madam, to construct a mnemonic memory circuit using stone knives and bearskins - Mr. Spock 1935 and me 2011 -
Thanks.... I think. Not so long ago I found one of my first creations on an ancient cassette tape. I transferred it to my PC as a sound file and reconstructed the binary from the sound samples with a little program I wrote. It runs well, even in an emulator and was found worthy to be included in the emulator's software folder. It certainly is not state of the art, but even my oldest programs were not as bad as that stuff below :)
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011 ---
I am endeavoring, Madam, to construct a mnemonic memory circuit using stone knives and bearskins - Mr. Spock 1935 and me 2011 -
CDP1802 wrote:
My first guess now is, that I must wire up the event after loading the form by finding the event handler method with reflection.
Yep, that'd probably be the way I'd go. As an alternative, you could give refer to the controls by their name. So, in your XAML you have this:
<Button
Name="MyButton"
Width="50"
Content="Click Me!" />Then in your C# code, you have this:
this.MainControl = SomeXamlHelper.LoadMyXaml(Config.XamlForThisClass);
Part of that
LoadMyXaml
method would load up all the sub-controls by theirName
. You could then refer to those controls by their name and wire up the handlers in the C#:(this.MainControl.FindControl("MyButton") as AwesomeButton).OnClick += new EventHandler(SomeMethodOfTheFormToHandleThisEvent);
Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.
... here is the XAML that defines the left form in the screenshot. It is now included as embedded resource and loading and displaying the form works fine. I'm going to start working on the events now.
<cTestForm Id="FrmLayoutTest" Alpha="200" BackColor="0, 74, 127, 255" BorderColor="95, 158, 160, 255" CaptionColor="0, 54, 107, 255"
TextColor="255, 215, 0, 255" Text="UI Test" TextAlignment="MIDDLE_CENTER" BarWidth="32" CaptionPosition="RIGHT"
Font="Arial_16_bold" FontSize="16" FontStyle="BOLD" Width="375" Height="250" PositionX="600" PositionY="125"
xmlns="clr-namespace:PraetorTest;assembly=PraetorTest"
xmlns:foc="clr-namespace:FoC.Praetor4UI.Controls;assembly=Praetor4UI"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<cTestForm.Controls>
<foc:cPraePanel Id="PnlCaptionPosition" Width="115" Height="145" BorderColor="95, 158, 160, 255" PositionX="5" PositionY="5"
BackColor="0, 0, 0, 0">
foc:cPraePanel.Controls
<foc:cPraeLabel Id="LblCaptionposition" BorderColor="255, 255, 255, 255" Font="Arial_10" FontSize="10" FontStyle="NORMAL"
Width="105" Height="18" PositionX="5" PositionY="5" ResizeEnable="NONE" Text="Caption Position"
TextAlignment="MIDDLE_CENTER" TextColor="255, 215, 0, 255" />
<foc:cPraeImageButton Id="BtnUp" BackColor="173, 216, 230, 255" BorderColor="255, 255, 255, 255" Height="31"
HighlightColor="255, 255, 255, 255" Image="Button_up" PositionX="41" PositionY="35"
Width="31" />
<foc:cPraeImageButton Id="BtnLeft" BackColor="173, 216, 230, 255" BorderColor="255, 255, 255, 255" Height="31"
HighlightColor="255, 255, 255, 255" Image="Button_left" PositionX="5" PositionY="71"
Width="31" />
<foc:cPraeImageButton Id="BtnRight" BackColor="173, 216, 230, 255" BorderColor="255, 255, 255, 255" Height="31"
HighlightColor="255, 255, 255, 255" Image="Button_right" MaxHeight="0" PositionX="77"
PositionY="71" Width="31" />
<foc:cPraeImageButton Id="BtnDown" BackColor="173, 216, 230, 255" BorderColor="255, 255, 255, 255" Height="31"