I am working on a WPF application. There are lots of tabs in my app. Each tab contains a grid.My app is Page based and there is no window. There are two pages in my app, One is main page which Xaml is this MainPage.xaml
<Page x:Class="App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="MainPage" Height="600" Width="1000" WindowHeight="600"
WindowWidth="1000" WindowTitle="CSP - LOGIN" Background="Black"></Page>
And Page2.xaml
<Page x:Class="App.Page2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
<Grid Background="Black">
<TabControl HorizontalAlignment="Left" Height="100" Margin="27,63,0,0" VerticalAlignment="Top" Width="100">
<TabItem Header="TabItem">
<Grid Background="#FFE5E5E5">
<Grid HorizontalAlignment="Left" Height="410.5" Margin="10,19.54,0,0" VerticalAlignment="Top" Width="766">
<Button Content="Add Item" HorizontalAlignment="Left" Margin="10,135.748,0,0" VerticalAlignment="Top" Width="75"/>
<Button Content="Remove Item" HorizontalAlignment="Left" Margin="10,177.208,0,0" VerticalAlignment="Top" Width="75"/>
<Button Content="Update Item" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="10,217.168,0,0"/>
</Grid>
</Grid>
</TabItem>
<TabItem Header="TabItem">
<Grid Background="#FFE5E5E5">
<Grid HorizontalAlignment="Left" Height="410.5" Margin="10,19.54,0,0" VerticalAlignment="Top" Width="766">
<Button Content="Add Item" HorizontalAlignment="Left" Margin="10,135.748,0,0" VerticalAlignment="Top" Width="75"/>
<Button Content="Remove Item" HorizontalAlignment="Left" Margin="10,177.208,0,0" VerticalAlignment="Top" Width="75"/>
<Button Content="Update Item" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="10,217.168,0,0"/>
</Grid>
</Grid>
</TabItem>
<TabItem Header="TabItem" HorizontalAlignment="Left" Height="19.96" VerticalAlignment="Top" Width="96">
<Grid Background="#FFE5E5E5">
<Grid HorizontalAlignment="Left" Height="410.5" Margin="10,19.54,0,0" VerticalAlignment="Top" Width="766">
<Button Content="Add Item" HorizontalAlignment="Left" Margin="10,135.748,0,0" VerticalAlignment="Top" Width="75"/>
<Button Content="Remove Item" HorizontalAlignment="Left" Margin="10,177.208,0,0" VerticalAlignment="Top" Width="75"/>
<Button Content="Update Item" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="10,217.168,0,0"/>
</Grid>
</Grid>
</TabItem>
</TabControl>
</Grid>
</Page>
As you can see each tab have two grid each. One Grid is generated by default and other is added by me to make items together.
I tried SizeToContent and other functions to get width and height dynamically when changed but when i add SizeToContent it gives error and SizeToContent dont show in code hinting. It gives error that it is no accessible.
I want my content in grid to be dynamic so if window size is changed there size also change.
I'll explain a few behavioural aspects of control properties:
Width
property on a control causes it to be fixed horizontally.Height
property on a control causes it to be fixed vertically.HorizontalAlignment
property on a control has various behaviour, depending on the value:Stretch
: Default Value. Causes the control to stretch horizontally in relation to its parent container. This option has no effect when theWidth
property has been set.Left
: Aligns the control towards the left within its parent container.Center
: Centers the control horizontally within its parent container.Right
: Align the control towards the right within its parent container.VerticalAlignment
property on a control has various behaviour, dpending on the value:Stretch
: Default Value. Causes the control to stretch vertically in relation to its parent container. This option has no effect when theHeight
property has been set.Top
: Aligns the control towards the top within its parent container.Center
: Centers the control vertically within its parent container.Bottom
: Aligns the control towards the bottom within its parent container.Margin
property on a control will position itself relatively depending on the type of parent container, which is too extensive to explain here.It's unclear to me how you wish to position your controls, but to answer your question: you may remove the
Width
,Height
,HorizontalAlignment
andVerticalAlignment
of a control to allow it to stretch horizontally and vertically in your window. For example:Just play around with these properties and you'll get the hang of it soon.