user3793935
user3793935

Reputation: 489

Maximize a window --> the Grid should grow with the Window C# WPF

i have a short question.

I have a Grid definied like this :

<Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

In this Grid is a lot of stuff like Buttons, Textboxes, Menubar, Datagrid and so on. My question is: When i maximize the Window, how can i provide a growing Grid?

All the stuff in the Grid is coppled with the margin of the Grid, so if i manually resize the Grid the stuff still stay on the right place, so i just need to now how to let the Grid grow with the Window if the user clicks on this sqaure in the top right of the window to maximize it :)

Edit:

XAML Usercontroll:

<UserControl x:Class="View.PatientListView"
             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" 
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             mc:Ignorable="d" d:DesignWidth="1625" Height="750">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Menu Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Width="Auto">
            <MenuItem Header="Datei">
                <!--<MenuItem.Icon>
                    <Image Source="datei.jpg" Width="20" Height="20"/>
                </MenuItem.Icon>-->
                <MenuItem Header="Suchoptionen" Click="MenuItem_Click" >
                    <MenuItem.Icon>
                        <Image Source="Suchfeld-Lupe.png"/>
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
        </Menu>
        <Grid Grid.Column="0" Grid.Row="1" Margin="-10,5,10,-5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1258*"/>
                <ColumnDefinition Width="367*"/>
            </Grid.ColumnDefinitions>
            <TextBox x:Name="teingabe" x:FieldModifier="public"  KeyboardNavigation.TabIndex="1" HorizontalAlignment="right" Height="23" Margin="0,40,130,0" TextWrapping="Wrap" Text="{Binding Suchstring, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="230" ToolTip="Mehrere Eingaben (max. 3) durch &quot;,&quot; Trennung: Datensatz1 , Datensatz2 , Datensatz3" TextAlignment="Left" Grid.Column="1">
                <TextBox.InputBindings>
                    <KeyBinding Gesture="Enter"
                 Command="{Binding Searchcommand}" />
                </TextBox.InputBindings>
            </TextBox>
            <TextBox x:Name="tAnrede" x:FieldModifier="public" KeyboardNavigation.TabIndex="9" HorizontalAlignment="Right" Height="23" Margin="0,400,190,0" TextWrapping="Wrap" Text="{Binding Anrede,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="170" IsEnabled="{Binding Einschalten}" VerticalAlignment="Top" TextAlignment="Left" Grid.Column="1"/>
            <TextBox x:Name="tKostentraegerlk" x:FieldModifier="public" KeyboardNavigation.TabIndex="4" HorizontalAlignment="Right" Height="22" Margin="0,175,10,0" TextWrapping="Wrap" Text="{Binding Kostentraegerlk, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="170" IsEnabled="{Binding Einschalten}" TextAlignment="Left" Grid.Column="1">
            </TextBox>
            <Button x:Name="start" Content="Suche" HorizontalAlignment="right" Margin="0,40,10,0" VerticalAlignment="Top" Width="110" Height="23" Command="{Binding Searchcommand}" Grid.Column="1">
            </Button>

After this there only more controlls.

The Window XAML:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:View="clr-namespace:View"
        x:Name="Window"  
        x:Class="StartApplication.MainWindow"
        Title="Verwaltung" Height="773" Width="1632" Closing="Window_Closing" KeyDown="Window_KeyDown" >
    <View:PatientListView x:Name="plistview" HorizontalAlignment="Left" VerticalAlignment="Top" Width="1622" Height="750"/>
</Window>

Edit: NVM i saw my mistake ... Wtf, im so blind. Sorry :(

Upvotes: 0

Views: 2536

Answers (1)

blindmeis
blindmeis

Reputation: 22445

the important stuff is where your grid is within. in the code below the grid resize with the window

  <Window>
   <Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    </Grid>
   </Window>

Upvotes: 2

Related Questions