By khaled mahmoud - Tuesday, November 24, 2009
I need to add custom propery in nshape
and
how to create custom shape with image
Thanks
|
By Ivo Milanov - Thursday, November 26, 2009
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
|
By Ivo Milanov - Thursday, November 26, 2009
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
|
By Wilhelm Vortisch - Friday, January 29, 2010
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
|
By Ivo Milanov - Wednesday, February 3, 2010
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; }
|
By Wilhelm Vortisch - Wednesday, February 17, 2010
Hi Ivo,
thanks, you have solved my problems with the property editor.
Regards
Wilhelm
|
By Douglas Earl - Monday, April 5, 2010
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
|
By Nevron Support - Tuesday, April 6, 2010
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)};
|
|