Home > database >  How to resize content when maximize window in WPF?
How to resize content when maximize window in WPF?

Time:09-01

I have this window and I would like to resize content ( fit it to the size of window ) when the user maximize this window , I've tried many solutions but any of them worked for me :

<Window x:Class="Window_Image"
         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="550" d:DesignWidth="550">
<Grid>
    <DockPanel LastChildFill="True" Name="ImgDock"  Background="Transparent" >
        <Image Source="../res/myimage.png" Width="450" Height="450" x:Name="ImageComp"  Visibility="Visible" > 
      </Image>
    </DockPanel>
</Grid>

One of solution that I've tried :

Unfortunatly , this solution didn't works for me.

CodePudding user response:

The issue was that the Image size was hardcoded (Height and Width properties).

By default, most of WPF's component will adjust their size to fill their containers.

  • Related