Creating a custom margin

SyntaxEditor for WPF Forum

Posted 10 years ago by James Deadman
Version: 9.2.0515
Avatar
Hi,

I am attempting to create a custom margin in SyntaxEdutir within our app. I copied across the custom margin and margin factory from your Sample app. However when i run the application the column doesnt seem to appear.

From some debugging it seems that in the CustomMargin::OnViewTextAreaLayout() function, the customDrawElement member is null and so no custom drawing is performed. I think this may be the reason but not too sure.

Can i please ask how i set up the customDrawElement within the custom margin, or if i have missed some initialisation please?

Thanks,
James

Comments (4)

Posted 10 years ago by James Deadman
Avatar
Additional info....

I have just noticed that the customDrawElement member seems to be set in the custom margin's OnApplyTemplate() function.

However the OnApplyTemplate() function is never called when running the App. Is there something else that i need to do or call please?

Please note that we dont use xaml in our application generally. Everything is added programmatically rather than by resources.

Thanks,
James


[Modified at 04/09/2010 05:52 AM]
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi James,

Did you set up a Style for your margin? You'll notice in our MainControl.xaml for the EditorViewMarginsCustom sample there is a resource entry for a CustomMargin style. That is what is creating the control template for the control. I suspect that is what you are missing.

On a side note, you could make a more low-level control that doesn't use a template and where you just programmatically create its visual tree. But the way in the demo is ceratainly easier.


Actipro Software Support

Posted 10 years ago by James Deadman
Avatar
Thanks for your help.

How might i set up a style for the custom margin please? I'm not sure i can use xaml as its a C#/C++ based project. How might i do this programmatically please to avoid the problem of using xaml? Would it be just a few lines of code?

Thanks!
James
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You may be able to use the techniques here:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/2643cebb-c7b0-4af8-8e63-9674570f3021
http://stackoverflow.com/questions/732736/define-a-wpf-controltemplate-at-runtime

If you don't do those then you'd have to look up articles on how to do really low level visual tree construction using methods like:
http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.getvisualchild.aspx

Using XAML is MUCH easier though.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.