2013-07-08 33 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,它似乎是工作。我對這些交互是如何引起我所看到的有點困惑。

相關問題