1
votes

I have defined a grid with row and columns:

<Grid Grid.Column="0">
  <Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto"/>
  </Grid.RowDefinitions>

  <DataGrid Name="dtgPPtab1" Grid.Row="0" FontSize="24" Background="{x:Null}" BorderBrush="Gainsboro" BorderThickness="5" Margin="10" AutoGeneratingColumn="Datagrid_AutoGeneratingColumn" SelectionChanged="Datagrid_SelectionChanged" ></DataGrid>
  <StackPanel Name="spPPtab1" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
    <Button Name="btPPPlayPause"  Content="&#xf144;" Foreground="Lime" FontSize="{StaticResource TEXTBOX_BIGBUTTON_FONTSIZE}"  Background="{x:Null}" BorderBrush="{x:Null}" Click="Button_Click"/>
    <Button Name="btPPStop"  Content="&#xF28D;" Visibility="Hidden" Foreground="Red" FontSize="{StaticResource TEXTBOX_BIGBUTTON_FONTSIZE}"  Background="{x:Null}" BorderBrush="{x:Null}" Click="Button_Click"/>
  </StackPanel>
  </Grid>

now I want to set the button btPPPlayPause at the runtime through code this way:

  1. from hidden to visible
  2. set a dimension` btPPPlayPause.Width = btPPPlayPause.Height = ...

As far as I know the rowdefinition height = auto should allow correct visualization. Instead what I see is:

  1. at design time this:

enter image description here

  1. at runtime time this:

enter image description here

so auto-adaptatin is not working. can anyone tell me why?

1
try to set the first height <RowDefinition Height="*"/> to Auto.StepUp
it's the same. It takes more space but it the circle is just not adapted to the size.Luca

1 Answers

2
votes

Every button has an inner padding. Additionally you are not setting the fontsize of the button and the height of the stackpanel.

 spPPtab1.Height = easyRunData.FontSize * 2 + btPPPlayPause.Padding.Top + btPPPlayPause.Padding.Bottom;
 btPPPlayPause.Width = btPPPlayPause.Height = (easyRunData.FontSize) * 2 + btPPPlayPause.Padding.Left + btPPPlayPause.Padding.Right;
 btPPPlayPause.FontSize = easyRunData.FontSize*2;

and for the xaml

<StackPanel Name="spPPtab1" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0" Background="Red">
 <Button Name="btPPPlayPause" Grid.Row="2" Content="&#xf144;" Foreground="Lime" Background="Blue" BorderBrush="Gainsboro"  FontSize="{StaticResource TEXTBOX_BIGBUTTON_FONTSIZE}" VerticalContentAlignment="Stretch"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Padding="5" HorizontalContentAlignment="Stretch" Margin="0" Click="Button_Click">
...

enter image description here