我有一个DockPanel,其行定义为LastChildFill =“true”,行中的最后一项是两个独立的控件,表示文件选择器 - 文件路径的TextBox,后跟显示打开文件的Button对话框(填充文本框)。我想将这组控件停靠在行的末尾,以便TextBox而不是Button被拉伸以填充空格。这可能吗?
<DockPanel Grid.Row="1"
Margin="3"
LastChildFill="True">
<!-- * additional controls omitted * -->
<TextBox x:Name="TExecutable"
Width="200"
VerticalContentAlignment="Center"
Text="{Binding Locale[event_SampleExecutable],
Source={StaticResource PluginViewModel}}"/>
<Button Margin="3 0 0 0"
VerticalContentAlignment="Center"
Command="{Binding SelectExecutableCommand}"
Content="{Binding Locale[event_SelectExecutableText],
Source={StaticResource PluginViewModel}}" />
</DockPanel>
答案 0 :(得分:2)
您需要做以下事情:
DockPanel.Dock="Right"
,使其位于textBox右侧。在textBox上设置DockPanel.Dock="Left"
。
<DockPanel Grid.Row="1"
Margin="3"
LastChildFill="True">
<!-- * additional controls omitted * -->
<Button Margin="3 0 0 0"
VerticalContentAlignment="Center"
DockPanel.Dock="Right"
Command="{Binding SelectExecutableCommand}"
Content="{Binding Locale[event_SelectExecutableText],
Source={StaticResource PluginViewModel}}" />
<TextBox x:Name="TExecutable"
DockPanel.Dock="Left"
VerticalContentAlignment="Center"
Text="{Binding Locale[event_SampleExecutable],
Source={StaticResource PluginViewModel}}"/>
</DockPanel>
答案 1 :(得分:2)
用Grid包裹:
<DockPanel
Margin="3"
LastChildFill="True">
<!-- * additional controls omitted * -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox x:Name="TExecutable"
VerticalContentAlignment="Center"
Text="{Binding Locale[event_SampleExecutable],
Source={StaticResource PluginViewModel}}"/>
<Button Margin="3 0 0 0" Grid.Column="1"
VerticalContentAlignment="Center"
Command="{Binding SelectExecutableCommand}"
Content="{Binding Locale[event_SelectExecutableText],
Source={StaticResource PluginViewModel}}" />
</Grid>
</DockPanel>