【问题标题】:Bottom DockPanel for Image control用于图像控制的底部 DockPanel
【发布时间】:2012-03-28 08:33:24
【问题描述】:

我想在Image 控件的底部有一个DockPanel(不透明):DockPanel 宽度应该等于当前Image 宽度。

这是 XAML:

<Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid>
    <Image Source="..." />

    <DockPanel VerticalAlignment="Bottom" LastChildFill="True" Opacity="0.5">
      <Button Content="Play" />
      <ProgressBar Value="50" Maximum="100" Height="40" />
    </DockPanel>
  </Grid>
</Window>

使用此 XAML:DockPanel 的宽度不等于 Image 的宽度。 DockPanel 宽度设置为 Window 宽度。

【问题讨论】:

  • 我缺少 Grid.Row="0" 属性。

标签: c# wpf xaml dockpanel


【解决方案1】:

这应该是你需要的(带绑定)

<Image Source="..." Name=myImg/> 


<DockPanel Width="{Binding ElementName=myImg, Path=ActualWidth}" VerticalAlignment="Bottom" LastChildFill="True" Opacity="0.5" > 

没有绑定的可能解决方案是

<Viewbox>
        <Grid>
            <Image Source=... /> 

            <DockPanel VerticalAlignment="Bottom" LastChildFill="True" Opacity="0.5" > 
              <Button Content="Play" /> 
              <ProgressBar Value="50" Maximum="100" Height="40" /> 
            </DockPanel>
        </Grid>
    </Viewbox>

【讨论】:

  • 谢谢!这行得通。但是有没有更优雅的解决方案?也许一些布局控制(网格、面板等)来解决这个任务?
  • 谢谢。我已经尝试了Viewbox 的解决方案。按钮文本大小和框架线宽在Viewbox 内缩放。如何解决这个问题?
  • 我明白了,这表明我可以使用数据绑定解决方案。
猜你喜欢
  • 1970-01-01
  • 2018-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-16
  • 2013-06-11
  • 1970-01-01
相关资源
最近更新 更多