Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Problem with custom component (Read 8688 times)
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Problem with custom component
Dec 16th, 2010 at 6:54am
Print Post  

Hello Stoyo.
Im continue working and learning about ths wonderfull diagram component ,and today i have new problems, after solve thsi problem i buy one licence for me, and i contact to sales team, for see if  possible buy a second licence for my brother, he i student and love this tool too.

I just create a simple component, this is suposed is a button, no is functional is just for test.

All work perfect i can create the custom button on the form etc etc, juts find some problem when try load xml file, this is the error mensaje

{"'Could not register named object. Cannot register duplicate name 'TextButon' in this scope.' Line number '1' and line position '500'."}Here is a example:


Here is the example.
http://www.4shared.com/file/654fNtaZ/Sample2.html

Rememebr for create button you need press shift key, this is your example with simple modification.
I apreciate if you can guide to em for solve this problem.
Best regards.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with custom component
Reply #1 - Dec 16th, 2010 at 10:37am
Print Post  
Hi,

You will have to avoid naming the usercontrol child controls if you want to use the built-in XamlWriter/XamlReader serialization, because they try to register the loaded names in some global Xaml namespace. This shows how you can do that by binding to property values instead of accessing the usercontrol elements from code:
https://mindfusion.eu/_samples/Sample2.zip

Otherwise you will have to implement your own serialization by handling the SerializeControl and DeserializeControl events.

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: Problem with custom component
Reply #2 - Dec 16th, 2010 at 4:32pm
Print Post  
Like always thankyou for your help.
Oh! this is really complex way to do this.
I already have developed complex components.
This way of avoid name of components is a big problem.

This limitatin probably make to me desist buy this mindfusion component.
This is really bad, mindfusion is wonderfull.

I already have very complex components developed, this way require recode all components !

Please can confimr if this is the only way?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with custom component
Reply #3 - Dec 16th, 2010 at 6:52pm
Print Post  
The other way is to implement serialization by handling the SerializeControl and DeserializeControl events.
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Problem with custom component
Reply #4 - Dec 16th, 2010 at 7:30pm
Print Post  
Ups, the 2 ways reuiere lot of code jijiji  Smiley
I have to recode all !   Sad
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Problem with custom component
Reply #5 - Dec 16th, 2010 at 9:03pm
Print Post  
Stoyo, after all use binding aparently no is super complex like i think   Grin

I back later with some questiosn probably.
But i test and no is a lot of work use binding in my components.

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


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Problem with custom component
Reply #6 - Dec 18th, 2010 at 1:46am
Print Post  
Stoyo me again, this time no is directly related with mindfusion component but im loosed  with c# code and binding

Here new example whit propertiesd binded:
http://www.4shared.com/file/DCgZKfAs/Sample3.html



Bsically what i need is 

button.Text = "Button" + form.Nodes.Count.ToString();    this is done form you

button.Stroke
button.Fill
button.FontSize
button.StrokeThickness
button.Foreground

All this is already binded in xaml, but is strange due some things work with extraa code and other no, and dont know why.

Learning how bind and handle all this properties i think i can rearrange all my components due basically is what i do need in all  my other components.

Pleasse if can fix the example, i apreciate.
I send a private mail to you, please check your mail

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Problem with custom component
Reply #7 - Dec 20th, 2010 at 9:29am
Print Post  
Hi,

These properties do not exist in the UserControl class, so you cannot bind to them without defining them first. E.g. add this to Mybutton.xaml.cs:

Code
Select All
static public DependencyProperty StrokeProperty = DependencyProperty.Register(
	"Stroke", typeof(Brush), typeof(Mybutton), new PropertyMetadata(Brushes.Black));

public Brush Stroke
{
	get { return (Brush)GetValue(StrokeProperty); }
	set { SetValue(StrokeProperty, value); }
} 



and then you will be able to set button.Stroke instead of button.Rectangle.Stroke in the code-behind, using the binding expression you already have in the xaml.

Also for such type of control you would be better off deriving from Control instead of UserControl, and defining the appearance using a control template instead of user-control xaml. Then the binding expressions would be much simpler, e.g.:

<Rectangle Stroke="{TemplateBinding Stroke}" />

A different way to simplify them while still deriving from UserControl is to set DataContext = this in control constructor. Then you can skip the RelativeSource part and it will look like this:

<Rectangle Stroke="{Binding Stroke}" />

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: Problem with custom component
Reply #8 - Dec 20th, 2010 at 11:11pm
Print Post  
Thnakyou!! testing this !!
  
Back to top
 
IP Logged
 
PDM.
Senior Member
****
Offline


I love YaBB 1G - SP1!

Posts: 256
Joined: Dec 2nd, 2010
Re: Problem with custom component
Reply #9 - Dec 21st, 2010 at 6:51am
Print Post  
Stoyo, your help here in the forum is really wonderfull
This way i think is my best for me : )
<Rectangle Stroke="{Binding Stroke}" />

Thankyou again for your great help !

I found new problems lol so i send some new questions in the next hours, im trying to solve the problem myself before send more questions.

Bets regards.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint