Question

I have a scenerio where I want to dynamically render a custom form object. This form is similar to a WinForms form. It will display one of more button bars, buttons can only live within a button bar in our implementation, and numerous edit control that the user will use for data entry.

In rendering the form we have in a configuration file a row height and column width, both as a pertcentage of the application area. All forms share a common row height and column width. The actual device unit value of these are calculated on applicaiton initialization.

My issue is with sizing the form. For example, I have a form that is supposed to be 15 rows by 80 columns, let's say this translates to 500 units high and 800 units wide. This would be the form area, not including button bars. Right now I am calculating the window height and width in a FormPreviewManager. However, it is cumbersome as I have to give the total units, including the size of the button bar(s) and the windows borders, which may change as they have the option of including a title bar or not in the floating form window.

Within the rendering of the form I use a DockPanel to render the button bar(s) and claim the remaining space as my grid of rows and columns. I tried creatign the button bar(s), setting the remaining space to my FormGrid object, then specifically setting the Width and Height for the FormGrid but it doesn't change the size of the containing window.

How can I make it so that the floating window sizes automatically? I want to be able to draw the button bar(s) then say remaining space is 500 units high and 800 units wide, the window then adjust to whatever size it needs to hold this data, no more and no less.

Any help on this, or a possible other approach, would be great.

Update

Basically if this was my entire XAML definition for my window I would like to be able to set the width and height of UnusedContent and have the window resize accordingly.

<Grid>
    <DockPanel>
        <StackPanel DockPanel.Dock="Top" Height="50" />
        <StackPanel DockPanel.Dock="Left" Width="50" />
        <ContentControl x:Name="UnusedContent" />
    </DockPanel>
</Grid>

If I set UnusedContent to 200 by 200 it would create a window with interior dimensions of 250 by 250, the content area plus the two stack panels.

Was it helpful?

Solution

You can try placing a control to fill up the remaining DockPanel space, and then binding to that control's ActualHeight and ActualWidth properties

<DockPanel>
    <StackPanel DockPanel.Dock="Top" Height="50" />
    <StackPanel DockPanel.Dock="Left" Width="100" />
    <ContentControl x:Name="Spacer" />
</DockPanel>

<Grid Height="{Binding ElementName=Spacer, Path=ActualHeight}"
      Width="{Binding ElementName=Spacer, Path=ActualWidth}" />

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top