将TextBlock放在另一个TextBlock的顶部

时间:2013-04-07 21:13:39

标签: wpf c#-4.0 visibility textblock dockpanel

我尝试实施一个案例,其中一个TextBlock出现在另一个TextBlock之上,并使用Visibility属性播放 - 但它还没有工作。

TextBlock位于DockPanel内:

<DockPanel Grid.Row="1" Margin="5">
    <TextBlock Text="Text1" Height="20" HorizontalAlignment="Right" DockPanel.Dock="Right">
        <TextBlock Text="Text2" Background="Aqua" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{Binding IfDeviceSelected, NotifyOnSourceUpdated=True, Converter={StaticResource  ResourceKey=BoolToVisibilityConverter}}" />
    </TextBlock>

    <TextBlock Text="@Device Focus:" Height="20" HorizontalAlignment="Right" DockPanel.Dock="Right" />
</DockPanel>

1 个答案:

答案 0 :(得分:2)

您需要使用Grid对这些TextBlocks进行分组,DockPanel/StackPanel不允许重叠控件(不会对边距进行可怕的操作等)

  <DockPanel Grid.Row="1" Margin="5" >
     <Grid DockPanel.Dock="Right" >
         <TextBlock Text="Text1" />
         <TextBlock Text="Text2" Background="Aqua" Visibility="{Binding IfDeviceSelected, NotifyOnSourceUpdated=True, Converter={StaticResource  ResourceKey=BoolToVisibilityConverter}}" />
     </Grid>
     <TextBlock Text="@Device Focus:" Height="20" HorizontalAlignment="Right" DockPanel.Dock="Right" />
  </DockPanel>