我有两个堆叠按钮,顶部按钮在TextBlock的左侧和右侧有图像。底部按钮左侧有一个图像,右侧有一个TextBlock。期望使顶部按钮上的TextBlock居中并拉伸以填充两个图像之间的空间。怎么办呢?
<ScrollViewer>
<Grid>
<Grid.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ControlLightColorKey}}"/>
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Button
HorizontalContentAlignment="Stretch"
Grid.Row="0"
Grid.Column="1"
Margin="2"
Height="{Binding Height, ElementName=Tb}"
Click="Button1_Click">
<!---->
<DockPanel>
<Image
Source="/images/block_arrow_left.png"
Grid.Row="0"
Grid.Column="0"
Height="{Binding ActualHeight, ElementName=Tb}"
Margin="0"
VerticalAlignment="Center"
HorizontalAlignment="Left">
</Image>
<TextBlock
x:Name="Tb"
Padding="5"
Grid.Row="0"
Grid.Column="1"
FontSize="14"
VerticalAlignment="Center"
Text="button1"/>
<Image
Source="/images/block_arrow_left.png"
Grid.Row="0"
Grid.Column="4"
Height="{Binding ActualHeight, ElementName=Tb}"
Margin="0"
VerticalAlignment="Center"
HorizontalAlignment="Right">
</Image>
</DockPanel>
</Button>
<Button
HorizontalContentAlignment="Stretch"
Grid.Row="1"
Grid.Column="1"
Margin="2"
Height="{Binding Height, ElementName=Tb}"
Click="Button2_Click">
<DockPanel>
<Image
Source="images/block_arrow_left.png"
VerticalAlignment="Center"
Grid.Row="1"
Grid.Column="0"
Height="{Binding ActualHeight, ElementName=Tb}" >
</Image>
<TextBlock
Padding="5"
Grid.Row="1"
Grid.Column="1"
FontSize="14"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Text="button22222222222222">
</TextBlock>
</DockPanel>
</Button>
</Grid>
</ScrollViewer>
答案 0 :(得分:2)
将DataFrame[id: bigint, test_time: bigint, status: string, pkg: string, test_type: string, test_name: string, test_id: bigint, test_value: double, test_times: bigint, desc: string, test_source: string, GP: double]
替换为DockPanel
,提供Grid
三列,将Grid
放在中间列,并将TextBlock
属性设置为{ {1}}:
HorizontalAlignment