wpf Grid resize with grid in stackpanel is removing minWidth property in the inside grid

754 views Asked by At

My Grid is looking like this and i want to work in the second column.

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

My code for second column is like this: when i resize my window the column just resize like i haven't set a minWidth in this grid. I want the image to stay visible and the first column(textbox) to resize first.

I want column 1 to stay visible the longest

<StackPanel Grid.Column="1" Margin="5,0,0,0">
   <Label Height="16" Style="{StaticResource InputLabel}" Content="Sup" />

   <Grid MinWidth="200">
      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="30" MinWidth="30" />
      </Grid.ColumnDefinitions>
      <Border Padding="5,2,0,0" Grid.Column="0" BorderThickness="4,0,0,0" Background"{StaticResource LightBackground}" BorderBrush="{StaticResource SupplierColor}">
         <TextBlock Background="White" Text="{Binding Name}" />
       </Border>
       <Button MinWidth="25" Grid.Column="1" Margin="5,0,0,0"
         cal:Message.Attach="[Event Click] = [Action Search]">
         <Image Source="{StaticResource Search-Tiny}" Width="16" />
    </Button>
  </Grid>
</StackPanel>
1

There are 1 answers

2
SamTh3D3v On BEST ANSWER

Setting the MinWidth in the second Grid to 200,somehow sets indirectly the MinWidth of the Border to (200 - 25 = 175), and that what makes the imageButton disappears from the view when re-sizing the window, you will get the expecting result if you don't set the MinWidth of the second grid, your Xaml should look like so :

<StackPanel Grid.Column="1" Margin="5,0,0,0">
   <Label Height="16" Style="{StaticResource InputLabel}" Content="Sup" />

   <Grid>
      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="30" MinWidth="30" />
      </Grid.ColumnDefinitions>
      <Border Padding="5,2,0,0" Grid.Column="0" BorderThickness="4,0,0,0" Background"{StaticResource LightBackground}" BorderBrush="{StaticResource SupplierColor}">
         <TextBlock Background="White" Text="{Binding Name}" />
       </Border>
       <Button MinWidth="25" Grid.Column="1" Margin="5,0,0,0"
         cal:Message.Attach="[Event Click] = [Action Search]">
         <Image Source="{StaticResource Search-Tiny}" Width="16" />
    </Button>
  </Grid>
</StackPanel>