我已经定义了一个包含行和列的网格:
<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="" Foreground="Lime" FontSize="{StaticResource TEXTBOX_BIGBUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Click="Button_Click"/>
<Button Name="btPPStop" Content="" Visibility="Hidden" Foreground="Red" FontSize="{StaticResource TEXTBOX_BIGBUTTON_FONTSIZE}" Background="{x:Null}" BorderBrush="{x:Null}" Click="Button_Click"/>
</StackPanel>
</Grid>
现在我想通过这样的代码在运行时设置按钮btPPPlayPause:
答案 0 :(得分:2)
每个按钮都有一个内部填充。 此外,您没有设置按钮的字体大小和堆栈面板的高度。
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;
和xaml
<StackPanel Name="spPPtab1" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0" Background="Red">
<Button Name="btPPPlayPause" Grid.Row="2" Content="" 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">
...