Miz*_*zor 31 wpf xaml dockpanel
在一个窗口中,我有一个DockPanels 列表来指定几个文件.每个DockPanel都有一个TextBox(用于路径)和一个按钮(用于浏览文件).
我重新创建了一个简单的WPF页面来解决这里的问题:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="150"
Height="22">
<DockPanel>
<TextBox HorizontalAlignment="Stretch"/> <!-- path to file -->
<Button Content="..." DockPanel.Dock="Right"/> <!-- button to browse for file -->
</DockPanel>
</Page>
Run Code Online (Sandbox Code Playgroud)
问题是我希望按钮位于文本框的右侧,但这会导致文本框非常小,因为DockPanel的LastChild是用完剩余空间的按钮.香港专业教育学院试图改变它,通过改变他们周围和设置,LastChildFill="False"但这只会导致按钮再次变小,而不是使文本框宽(甚至与HorizontalAlignment="Stretch").
我想按顺序控制的原因是我希望用户在使用tab窗口导航时到达Button之前的TextBox .我调查了设置,TabIndex但感觉很讨厌,WPF最喜欢的功能是tabindex的顺序是在XAML中定义的conrols.更不用说我可能不得不在Window中的所有内容上手动设置TabIndex.
对我来说,似乎不遵守TextBox.HorizontalAlignment的设置.如何让第一个控件尽可能多地使用空间但仍保留Tab键顺序?
小智 41
像这样:
<DockPanel LastChildFill="True">
<Button Content="..." DockPanel.Dock="Right"/> <!-- button to browse for file -->
<TextBox DockPanel.Dock="Left" HorizontalAlignment="Stretch"/> <!-- path to file -->
</DockPanel>
Run Code Online (Sandbox Code Playgroud)
Joh*_*wen 26
如果您不想要DockPanel的行为,请不要使用DockPanel.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox />
<Button Content="..." Grid.Column="1"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13603 次 |
| 最近记录: |