【问题标题】:WPF align items in containerWPF 对齐容器中的项目
【发布时间】:2014-08-20 20:45:12
【问题描述】:

所以我有这个简单的 xaml:

    <TextBox Grid.Row="0" Grid.Column="1" Margin="10,14,10,5" BorderBrush="Magenta" BorderThickness="1" >
        <TextBox.Text >
            <Binding Path="Name" NotifyOnTargetUpdated="True" UpdateSourceTrigger="PropertyChanged" >
                <Binding.ValidationRules>
                    <DataErrorValidationRule ValidatesOnTargetUpdated="False"  />
                </Binding.ValidationRules>
            </Binding>
        </TextBox.Text>
    </TextBox>

    <Border Grid.Row="1" Grid.Column="1" BorderThickness="1" BorderBrush="Lime" Margin="10, 0, 10, 0">
        <DockPanel  Margin="0"  >
            <Button  Margin="0, 0, 5, 0" Width="100" Content="First" />
            <Button  DockPanel.Dock="Right" Width="100" Content="Second" />
        </DockPanel>
    </Border>

看起来是这样的:

我想以这样的方式放置按钮,即第一个按钮左对齐,第二个按钮右对齐。但如您所见,第二个按钮和边框右侧之间有一个空格。我怎么能杀死这个空间?预先感谢!

【问题讨论】:

    标签: wpf xaml styles border


    【解决方案1】:

    这是因为LastChildFillDockPanel)默认为 true,从而导致该行为。 可以设置为false来解决问题:

    <DockPanel  Margin="0" LastChildFill="False">
            <Button  Margin="0, 0, 5, 0" Width="100" Content="First" />
            <Button  DockPanel.Dock="Right" Width="100" Content="Second" />
    </DockPanel>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-14
      • 2017-08-21
      • 2014-05-31
      • 2022-01-24
      • 1970-01-01
      • 2015-07-10
      • 1970-01-01
      相关资源
      最近更新 更多