2013-07-08 101 views
0

因此,我试图让我的轴平面在ScrollViewer中绘制,然后我想进入并绘制轴线空间中的信号列表被绘制,以便信号在轴的顶部。我认为正确的做法是使用ZIndex,但我必须做错事。如何使控件在grid中正确重叠使用zindex

http://picpaste.com/signalgraph1-HSFHBYOG.JPG

基本上,它看起来像轴是ScrollViewer大小像我想要的,但随后的StackPanel被放置,而不是放在75个单位下来像我期望的轴后,。

这是怎么发生的?我怎样才能得到我想要的行为?

  <ScrollViewer 
       x:Name="signal_scrollviewer" 
       Focusable="False" 
       CanContentScroll="False"> 
       <Grid> 
       <Grid.RowDefinitions> 
        <RowDefinition Height="75" /> 
        <RowDefinition Height="*" /> 
       </Grid.RowDefinitions> 
       <wpfExp:SignalGraphAxis Grid.ZIndex="1" 
             Grid.Row="0" 
             Grid.RowSpan="2" 
             x:Name="signal_axis" 
             Height="{Binding ElementName=signal_scrollviewer, Path=ActualHeight}" 
             signal_graph_window_width="{Binding RelativeSource = {RelativeSource AncestorType={x:Type ScrollViewer}}, Path=ActualWidth}" 
             GraphHeight ="{Binding ElementName=graph_viewer, Path=GraphHeight, Mode=OneWay}" 
             PenColor="{Binding ElementName=GraphColorPicker, Path=SelectedColor, Mode=OneWay}" 
             PenWidth="{Binding ElementName=graph_viewer, Path=GraphPenWidth, Mode=OneWay}" 
             X_Scale="{Binding ElementName=graph_viewer, Path=X_Scale, Mode=OneWay}" 
             MaxTimeValue="{Binding ElementName=graph_viewer, Path=_SignalDataViewModel.MaxTimeValue, Mode=OneWay}" 
        /> 
       <StackPanel Background="Transparent" Grid.ZIndex="2" Grid.Row="1"> 
        <ItemsPresenter /> 
       </StackPanel> 
       </Grid> 
      </ScrollViewer> 
+1

请勿在网格中使用ZIndex。网格按顺序排列它的子节点,所以如果你只是把你的Axis控件放在xaml的实际内容之前,它将会在轴控件的“顶部”放置实际的内容。哦,这是控制的是在OFC – Viv

+0

同一网格单元,但我想的是只控制重叠的一部分。那可能吗?我希望轴在0排发车,但在第1行的部分将在连续获得书面之上由StackPanel的1 –

+0

星爷尝试设置'Grid.RowSpan =“2”'你的主轴元件。现在,在0行仅轴元素行1两轴元素,你的'StackPanel'存在,并在XAML之前'StackPanel'发生轴向元件但是存在,这将是后面的'StackPanel'第1行中 – Viv

回答

1

薇薇正在写一个很好的解决方案,但你需要设置Grid.RowSpan="2"StackPanel元素,一切都将正常工作。

<ScrollViewer 
      x:Name="signal_scrollviewer" 
      Focusable="False" 
      CanContentScroll="False"> 
      <Grid> 
      <wpfExp:SignalGraphAxis 
            x:Name="signal_axis" 
            Height="{Binding ElementName=signal_scrollviewer, Path=ActualHeight}" 
            signal_graph_window_width="{Binding RelativeSource = {RelativeSource AncestorType={x:Type ScrollViewer}}, Path=ActualWidth}" 
            GraphHeight ="{Binding ElementName=graph_viewer, Path=GraphHeight, Mode=OneWay}" 
            PenColor="{Binding ElementName=GraphColorPicker, Path=SelectedColor, Mode=OneWay}" 
            PenWidth="{Binding ElementName=graph_viewer, Path=GraphPenWidth, Mode=OneWay}" 
            X_Scale="{Binding ElementName=graph_viewer, Path=X_Scale, Mode=OneWay}" 
            MaxTimeValue="{Binding ElementName=graph_viewer, Path=_SignalDataViewModel.MaxTimeValue, Mode=OneWay}" 
       /> 
      <StackPanel Background="Transparent" Margin="0 75 0 0"> 
       <ItemsPresenter /> 
      </StackPanel> 
      </Grid> 
     </ScrollViewer> 
+0

但我想堆叠面板从顶部开始75。如果我只是将rowspan设置为2,它将从0开始,并占用网格中的所有空间。这是我想要取2行signalgraphaxis,所以这就是为什么我把行跨度= 2,但我越来越怪异的行为,其中的StackPanel是在页面的中间,如图那张照片我联系。 –

+0

你需要把75的边距然后,我已经更新了样本 –

0

所以,当我改变了这种结合:

Height="{Binding ElementName=signal_scrollviewer, Path=ActualHeight}" 

绑定Height而不是ActualHeight,它似乎是工作。我对这些交互是如何引起我所看到的有点困惑。