Profile Picture

Add Custom Property in NShape Object !!

Posted By khaled mahmoud 15 Years Ago
Author
Message
Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Douglas,

When saving and loading in XML format the custom types must be explicitly declared with the persistency manager serializer like this:

// IMPORTANT: custom types added to the DOM must be registered
// in the persistency manager if you intend to save/load in XML format
persistencyManager.Serializer.XmlExtraTypes = new Type[] {typeof(MyTag)};

Best Regards,
Nevron Support Team



Douglas Earl
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)

Group: Forum Members
Last Active: 10 Years Ago
Posts: 15, Visits: 1

Hi Ivo,

I tried the above and it doesn't work when saving to .ndx format.  The .net serializer throws an exception:

"The type UCT.Diagramming.MyTag was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."

I'm not sure where I'd add the XmlInclude attribute since if I understand correctly it would have to be on one of your classes.  Do you know if adding a Tag object such as above is possible when saving to .ndx format?

Thanks,

Doug



Wilhelm Vortisch
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 14, Visits: 1
Hi Ivo,

thanks, you have solved my problems with the property editor.

Regards

Wilhelm

Ivo Milanov
Posted 14 Years Ago
View Quick Profile
Forum Member

Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)

Group: Forum Members
Last Active: 2 Months Ago
Posts: 35, Visits: 15
Hi Wilhelm,

Yes sure - the default diagram property grid uses the PropertyGrid of the .NET framework. If you define a Tag object to each shape then you need to simply subscribe for the NodeSelected and NodeDeselected events of the view event sink service. For a form on which you have dropped a PropertyGrid control use this code (also demonstrates how to make a custom tag):

private void Form1_Load(object sender, EventArgs e)
{
...
// assing a tag to a shape (actually you can assign a tag to all diagram elements)
shape.Tag = new MyTag();

// subscribe for the node selected/deselected events
nDrawingView1.EventSinkService.NodeSelected += new Nevron.Dom.NodeEventHandler(EventSinkService_NodeSelected);

nDrawingView1.EventSinkService.NodeDeselected += new Nevron.Dom.NodeEventHandler(EventSinkService_NodeDeselected);
}

void EventSinkService_NodeDeselected(Nevron.Dom.NNodeEventArgs args)
{
propertyGrid1.SelectedObject = null;
}

void EventSinkService_NodeSelected(Nevron.Dom.NNodeEventArgs args)
{
NDiagramElement element = args.Node as NDiagramElement;
if (element == null)
return;

propertyGrid1.SelectedObject = element.Tag;
}

[Serializable]
public class MyTag : ICloneable
{
public MyTag()
{
}
public object Clone()
{
MyTag clone = new MyTag();
clone.m_BoolField = this.m_BoolField;
clone.m_StringField = this.m_StringField;
return clone;
}
public bool BoolProperty
{
get
{
return m_BoolField;
}
set
{
m_BoolField = value;
}
}
public string StringProperty
{
get
{
return m_StringField;
}
set
{
m_StringField = value;
}
}
bool m_BoolField;
string m_StringField;
}

Wilhelm Vortisch
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 14, Visits: 1
Hi Ivo,

I have the request of displaying more then one (or two) own properties in the property editor.
The predefined properties of a shape should not be displayed, because they are not relevant for our solution.

Can I write my "own" propererty editor based on the nevron property editor?

Kind regards,

Wilhelm

Ivo Milanov
Posted 15 Years Ago
View Quick Profile
Forum Member

Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)

Group: Forum Members
Last Active: 2 Months Ago
Posts: 35, Visits: 15
As for applying an image to a shape - you can apply an image filling to any shape -> for example you can use the NRectangleShape and set its Style.FillStyle property to an NImageFillStyle object - see this topic in the help:

Framework > Presentation Layer > Graphics > Appearance Styles > Fill Styles > Image Fill Style

Best regards,
Ivo

Ivo Milanov
Posted 15 Years Ago
View Quick Profile
Forum Member

Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)

Group: Forum Members
Last Active: 2 Months Ago
Posts: 35, Visits: 15
Hi Khaled,

You can assign any custom object to the Tag property of any diagram element. The only requirement is that if the object is from a reference type it must implement a default constructor and also implement the ICloneable interface. For tag objects that need to be serialized the object must be marked as [Serializable].

Best regards,
Ivo

khaled mahmoud
Posted 15 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 3, Visits: 1
I need to add custom propery in nshape

and

how to create custom shape with image


Thanks



Similar Topics


Reading This Topic