Using auto height/width in WPF

SyntaxEditor for WPF Forum

Posted 14 years ago by James Deadman

Im just having a go with the WPF SyntaxEditor after coming from the WinForms SyntaxEditor. Im attempting to get the SyntaxEditor control (which is a member of my CView class) to auto-size to the parent window.

In the WinForms version its just a case of setting the 'Anchor' and 'Dock' properties to fill the window. How might i do this programmatically for WPF please? Is there a particular property i need to set?

I tried setting the 'Width' and 'Height' properties equal to "System::Double::NaN" but it didnt seem to work.


Comments (5)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Hi James,

Any control will auto-size to its parent Window if you don't set a Width/Height on it. If you want to have toolbars in there too you could have something like:
  <ToolBar DockPanel.Dock="Top" />
  <editor:SyntaxEditor />

Actipro Software Support

Posted 14 years ago by James Deadman

Thanks for your reply.

I'm oming from a WinForms SyntaxEditor background, i usually set the properies code-wise rather than via the XML language definition (im unsure how/where to add this in).

I have a function that creates the SyntaxEditor dynamically, like this:

m_wpfSyntaxEditor = gcnew ActiproSoftware::Windows::Controls::SyntaxEditor::SyntaxEditor;

// Add splitter
view->m_wpfSyntaxEditor->CanSplitHorizontally = true;
view->m_wpfSyntaxEditor->CanSplitVertically = true;

//Set height/width
view->m_wpfSyntaxEditor->Width = 800;
view->m_wpfSyntaxEditor->Height = 600;

I have tried not setting the Width and Height members but it still appears as a very small square in the top-left of my parent view.

Any further help would be appreciated, thanks.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
In WPF, layouts are much more dynamic than WinForms. So in most cases you do not ever want to set a Width or Height. Especially if you are trying to have something auto-size since that would prevent it from auto-sizing.

If you set a Window.Content property to a SyntaxEditor, it will fill it. However my guess is that your "view" is not a Window and is some other thing that maybe you set some alignment left/top on or something. Thus a small square could be created when the layout routines run. You'd want to use Stretch alignments on your view if it is within a Window and don't give it any explicit sizes.

Actipro Software Support

Posted 14 years ago by James Deadman
Thanks again for your reply.

You are corret, the parent window is actually an MFC CWinFormsView. I guess it doesnt necessarily work in the same way.

I think i've figured it out however. Just to let you know in case anyone else wants to do something similar.

I created a .NET UserControl in which i placed a .NET 'HostElement' object (i found some code on google). Within this i created the SynaxEditor object. It seems to work and fill the entire window (just have some more checking to do on it though!).

Thanks for your help.

Posted 14 years ago by James Deadman
Apologies that was meant to be an 'ElementHost' rather than 'HostElement'!
The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.