【发布时间】:2018-08-04 18:51:09
【问题描述】:
我有一个用 c# 编写的 WPF 应用程序。我需要创建一个具有全宽背景的工具栏,其中工具栏按钮位于中间。
这是我的XAML 代码
<ToolBarPanel ToolBarTray.IsLocked="True"
Style="{StaticResource ContentRoot}">
<ToolBar VerticalAlignment="Center"
HorizontalAlignment="Center"
Loaded="ToolBar_Loaded"
MinWidth="{Binding RelativeSource={RelativeSource AncestorType={x:Type ToolBarTray}}, Path=ActualWidth}">
<StackPanel Orientation="Horizontal">
<Button VerticalAlignment="Center"
Command="{Binding StepBackward}"
ToolTipService.ToolTip="Go to previous page"
ToolTipService.Placement="Mouse"
Height="32">
<fa:FontAwesome Icon="StepBackward"
FontSize="18" />
</Button>
<Button VerticalAlignment="Center"
HorizontalAlignment="Center"
Command="{Binding Backward}"
ToolTipService.ToolTip="Go to first page"
ToolTipService.Placement="Mouse"
Height="32">
<fa:FontAwesome Icon="Backward"
FontSize="18" />
</Button>
<TextBox Text="{Binding PageNumber}"
Width="50"
TextAlignment="Center"
VerticalAlignment="Center"
Padding="0, 4"
IsReadOnly="True"
ToolTipService.ToolTip="Current selected page"
ToolTipService.Placement="Mouse"
Height="32" />
<Label Content="{Binding OfPageCount}"
Padding="5"
Height="32" />
<Button VerticalAlignment="Center"
Command="{Binding Forward}"
ToolTipService.ToolTip="Go to last page"
ToolTipService.Placement="Mouse"
Height="32">
<fa:FontAwesome Icon="Forward"
FontSize="18" />
</Button>
<Button VerticalAlignment="Center"
Command="{Binding StepForward}"
ToolTipService.ToolTip="Go to next page"
ToolTipService.Placement="Mouse"
Height="32">
<fa:FontAwesome Icon="StepForward"
FontSize="18" />
</Button>
<ComboBox ItemsSource="{Binding PageSizes}"
SelectedItem="{Binding SelectedPageSize, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
DisplayMemberPath="Text"
SelectedValuePath="Value"
VerticalAlignment="Center"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
Width="75"
Padding="0, 5"
ToolTipService.ToolTip="Show selected amount of records per page"
ToolTipService.Placement="Mouse"
Height="32" />
<ComboBox ItemsSource="{Binding Pages}"
SelectedItem="{Binding SelectedPage, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
DisplayMemberPath="Text"
SelectedValuePath="Value"
VerticalAlignment="Center"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
Width="75"
Padding="0, 5"
ToolTipService.ToolTip="Go to selected page"
ToolTipService.Placement="Mouse"
Height="32" />
<Label Content="{Binding OfItemCount}"
Padding="5"
Height="32" />
</StackPanel>
</ToolBar>
</ToolBarPanel>
我的代码将中心的按钮显示为已用,但背景“ToolBarPanel”并没有按照需要一直延伸到我的屏幕上。
如何拉伸工具栏上的背景?
【问题讨论】: