3
\$\begingroup\$

I currently have this code:

<Window x:Class="Listener.MainWindow"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 Title="MainWindow" Height="600" Width="800" Loaded="Window_Loaded" WindowStyle="None" AllowsTransparency="True" Background="Transparent" MouseDown="Window_MouseDown" KeyDown="Window_KeyDown" ResizeMode="CanResizeWithGrip">
 <Grid Margin="30" x:Name="bgBorder">
 <Grid Margin="0" Background="#555555" x:Name="mainWindow" MouseDown="mainWindow_MouseDown">
 <Grid Margin="2,2,2,2" Height="80" Background="#779999" x:Name="topControl" VerticalAlignment="Top">
 </Grid>
 <Grid Margin="2,84,238,2" Background="#557777" x:Name="playListControl">
 </Grid>
 <Grid Margin="2,84,2,2" Width="234" Background="#668888" x:Name="optionsControl" HorizontalAlignment="Right">
 </Grid>
 </Grid>
 </Grid>
</Window>

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.

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Jan 22, 2015 at 12:21
\$\endgroup\$

2 Answers 2

5
\$\begingroup\$

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:

<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>

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.

answered Jan 22, 2015 at 14:32
\$\endgroup\$
1
  • \$\begingroup\$ Well it is working, but yea i will use this. \$\endgroup\$ Commented Jan 23, 2015 at 6:10
3
\$\begingroup\$

İf You Use a ViewBox and a Canvas on your user control, this will fix all the mainwindow sizes.

<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">
 <canvas>
 --- all your controls -- 
 </Canvas>
</Viewbox>
chicks
2,8593 gold badges18 silver badges30 bronze badges
answered May 15, 2019 at 9:57
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.