Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic XamlWriter/XamlReader serialization  and events (Read 6825 times)
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
XamlWriter/XamlReader serialization  and events
Dec 25th, 2010 at 1:27am
Print Post  
MERRY XMAS FOR EVERYBODY !!

Im continue testing and working based on FORM editor example, i have my custom button created with some properties correctly handled for be saved in XamlWriter/XamlReader serialization

But what about events?

Im testing with different kinds of events, like touch or mouse events, when the button is created, work perfect, mouseclick event is handled correctly, and button work, when i save and load again, button stop work.

Why?

<Rectangle Fill="Black" RadiusY="5" RadiusX="5" Stroke="White" StrokeThickness="2" Opacity="0.01" MouseLeftButtonDown="Rectangle1" />



XamlWriter/XamlReader serialization provided by mindfusion can save mouse events and other kind of events?


For simple custom components i try this:

this.MouseLeftButtonDown += new EventHandler<MouseEventArgs>(Mouse_down);

Work erfect when node is created, but after save and reload again nto work never again.

In some complex custom controls i build the situation is more complex, example:


<Grid Margin="82,156,188,213">



<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Stroke="Black" Width="74"/>



<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Margin="89,0,0,0" Stroke="Black" Width="74"/>



<Rectangle Fill="#FFF4F4F5" Margin="0,0,99,0" Stroke="Black" HorizontalAlignment="Right" Width="74"/>



<Rectangle Fill="#FFF4F4F5" Stroke="Black" HorizontalAlignment="Right" Width="74"/>


</Grid>

In this example imagine this is the custom component where i need do specic and different things when specific rectangle is clicked.

In this scenario in normal situation i do something like this:


<Grid Margin="0,0,0,0">

<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Stroke="Black" Width="74" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown1"/>

<Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Margin="89,0,0,0" Stroke="Black" Width="74" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown2" />

<Rectangle Fill="#FFF4F4F5" Margin="0,0,99,0" Stroke="Black" HorizontalAlignment="Right" Width="74" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown3" />

<Rectangle Fill="#FFF4F4F5" Stroke="Black" HorizontalAlignment="Right" Width="74" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown4" />
</Grid>

I cant find the way to do this with mindfusion.
Hoppe you can showme the solution for two situations, please, with code : )
Im very clsoe to test if mindfusion do all what i need,  i need sty secure at 100% before complete order.
« Last Edit: Dec 27th, 2010 at 12:11am by PDM. »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: XamlWriter/XamlReader serialization  and event
Reply #1 - Dec 27th, 2010 at 1:48pm
Print Post  
XamlReader and XamlWriter are standard components of WPF. Unfortunately while XamlReader can parse and set event handlers, XamlWriter cannot save them so they will be lost after reload.

You will either have to reassign the handlers after loading or pasting a control, or implement custom save/load code through the SerializeControl and DeserializeControl events. Since you already add 6-7 lines of code to define a dependency property and bind to it, it's not that much more work to add one more line per property to serialize it.

Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: XamlWriter/XamlReader serialization  and event
Reply #2 - Dec 27th, 2010 at 5:15pm
Print Post  
"Since you already add 6-7 lines of code to define a dependency property and bind to it, it's not that much more work to add one more line per property to serialize it"


Can show some example, im 100% loosed withs erialization jijij


About mindfusion is perfect, now i have to polish some things and see how serialize my components.
Sime example about what you comment please?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: XamlWriter/XamlReader serialization  and event
Reply #3 - Dec 27th, 2010 at 7:17pm
Print Post  
Here's an example:
https://mindfusion.eu/_samples/serialize_control.zip

Check the form_SerializeControl implementation and the Save and Load methods in Mybutton.cs.
There you must add calls to respectively Write or Read methods for each new property in Mybutton. You can implement the same interface in your other controls.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: XamlWriter/XamlReader serialization  and event
Reply #4 - Dec 28th, 2010 at 7:54am
Print Post  
try that example, but not understand yet how bind mouse events:

Example:

Text="{Binding Text}"
And code is:

static public DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(Mybutton), new PropertyMetadata(""));

public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}

But for events, like simple mouse click?

MouseLeftButtonDown="{Binding Click}">

Error1MouseLeftButtonDown="{Binding Touch}" is not valid. '{Binding Touch}' is not a valid event handler method name.

And c# code should be?

Im stuck in how bind event.

I know this is a C# question not mindfusion component question but really apreciate if explain how bind mouse events, so i cna have a btton functional again.

Bst regards.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: XamlWriter/XamlReader serialization  and event
Reply #5 - Dec 28th, 2010 at 8:40am
Print Post  
You should not handle the events differently. Just leave them as they were, set to the name of the handler method. Now when you load a control, it is created from its original Xaml code, and then the Load methods read only the property values that should differ.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: XamlWriter/XamlReader serialization  and event
Reply #6 - Dec 28th, 2010 at 10:34am
Print Post  
Great, is working now : )
Thankyou!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint