HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Creating automatic resizing of subelements in WPF

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
resizingcreatingwpfautomaticsubelements

Problem

I currently have this code:















A borderless window where the 3 sub panels get resized according to their margin and alignment.

Is this the correct way of doing this?

And on a side node, I plan on creating some sort of border resize and not use

ResizeMode="CanResizeWithGrip"


This was just used for testing.

Solution

I would say no. If you want to create grid-like layout, you should declare columns and rows, and specify how wpf should stretch those. For example like this:


    
        
            
            
            
            
        
        
        
            
                
                
                
                
            

            
            
        
    


You should really do some reading on how things are done in wpf, this HTML-ish layout you are trying to create won't work.

Code Snippets

<Grid Margin="30" x:Name="bgBorder">
    <Grid Background="#555555" x:Name="mainWindow" MouseDown="mainWindow_MouseDown">
        <Grid.RowDefinitions>
            <!-- frist row will stretch to fit the content -->
            <RowDefinition Height="Auto"/>
            <!-- second row will fill all available space -->
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid Margin="2" Grid.Row="0" Height="80" Background="#779999" x:Name="topControl"/>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <!-- first column will fill all available space -->
                <ColumnDefinition Width="*"/>
                <!-- second column will stretch to fit the content -->
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="0" Margin="2" Background="#557777" x:Name="playListControl"/>
            <Grid Grid.Column="1" Margin="2" Width="234" Background="#668888" x:Name="optionsControl"/>
        </Grid>
    </Grid>
</Grid>

Context

StackExchange Code Review Q#78310, answer score: 5

Revisions (0)

No revisions yet.