2009-04-06 15 views
0

GridSplitterの表示に関する問題があります。WPF GridSplitter visiblity

この場合、私はWinform DataGridViewをホストしています。 GridSplitterは、ドラッグされたときに他のコントロールで適切に表示されます。しかし、このグリッドではありません。実際、Datagridviewの代わりに私がホストしているものが一番上のコントロールになり、GridSplitterがその背後に隠れるようになります。

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Name="rowForButton"/> 
     <RowDefinition Name="rowForGridSplitter" Height="Auto" MinHeight="81" /> 
    </Grid.RowDefinitions> 
    <Button Grid.Row="0" Height="50" Width="110" Content="Button in First Row"/> 
    <my:WindowsFormsHost Panel.ZIndex="0" Grid.Row="1" Margin="30,11,138,0" x:Name="winHost" Height="58" VerticalAlignment="Top" OpacityMask="Transparent">    
     <win:DataGridView x:Name="dataGridView"></win:DataGridView> 
    </my:WindowsFormsHost>   
    <GridSplitter BorderThickness="1" Panel.ZIndex="1" Grid.Row="1" HorizontalAlignment="Stretch" Height="5" ShowsPreview="True" VerticalAlignment="Top"> 
    </GridSplitter> 
</Grid> 
+0

ことはあなたのXAMLの簡易版を投稿してください。 –

+0

元の質問をコードスニペットで編集しました。 –

答えて

0

Windowsフォームコントロールは常にWPFコントロールから別々にレンダリングされ、結果として常にWPFアプリケーション上に表示されます。

詳細については、Hosting a Microsoft Win32 Window in WPF(小文字のの出力動作での相違点)を参照してください。あなたの状況では

1

通常、GridSplitterを独自のグリッドセルに配置するか、余白を介してコントロールが重複しないようにする必要があります。しかし、私はそれがあなたにここに当てはまるかどうかはわかりません。 hereも参照してください。

+0

私はGridSplitterが適切に表示されるように、これらの3つの方法を試しました。それは何の違いもありません。 –

0

WPFネイティブのDataGridコントロールを使用してみてください。あなたが買うことができる、またはあなたが(現在はまだCTPで)マイクロソフトが提供するものを見てみることができ、市販のサードパーティ製のコントロールがいくつかあります:

0

、最速の修正はボタンで行にGirdSplitterを移動するには、次のようになります。

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Name="rowForButton"/> 
     <RowDefinition Name="rowForGridSplitter" Height="Auto" MinHeight="81" /> 
    </Grid.RowDefinitions> 
    <Button Grid.Row="0" Height="50" Width="110" Content="Button in First Row"/> 
    <my:WindowsFormsHost Panel.ZIndex="0" Grid.Row="1" Margin="30,11,138,0" x:Name="winHost" Height="58" VerticalAlignment="Top" OpacityMask="Transparent">    
     <win:DataGridView x:Name="dataGridView"></win:DataGridView> 
    </my:WindowsFormsHost>   
    <GridSplitter BorderThickness="1" Panel.ZIndex="1" Grid.Row="0" HorizontalAlignment="Stretch" Height="5" ShowsPreview="True" VerticalAlignment="Bottom"> 
    </GridSplitter> 
</Grid> 

今だけのボタンとグリッドスプリッタの間にいくつかのスペースがあることを確認するために余白を調整。

+0

Kellls、これは何の違いもありません。 グリッドスプリッターはコントロールの後ろに隠れています。 –

1

私は私の解決策があり、また、この問題が発生しました:

var splitter = new GridSplitter() 
     { 
      HorizontalAlignment = HorizontalAlignment.Stretch, 
      VerticalAlignment = VerticalAlignment.Stretch, 
      FocusVisualStyle = null, 
      ShowsPreview = true, 
      Background = new SolidColorBrush(new Color() { R = 1, G = 1, B = 1, A = 1 }), 
     }; 

// non-style/essential window which will display over your WinForm control 
var PopupWindowForSplitter = new PopupWindow() 
     { 
      Background = new SolidColorBrush(new Color() { R = 1, G = 1, B = 1, A = 1 }), 
      Visibility = Visibility.Collapsed 
     }; 
PopupWindowForSplitter.Show(); 
... 

Point _ptForSplitterDrag = new Point(0,0); 

splitter.DragStarted += (o, e) => 
     { 
      var pt = splitter.PointToScreen(new Point()); 
      _ptForSplitterDrag = splitter.PointToScreen(Mouse.GetPosition(splitter)); 
      PopupWindowForSplitter.Left = pt.X; 
      PopupWindowForSplitter.Top = pt.Y; 
      PopupWindowForSplitter.Height = splitter.ActualHeight; 
      PopupWindowForSplitter.Width = splitter.ActualWidth; 
      PopupWindowForSplitter.Activate(); 
      PopupWindowForSplitter.Visibility = Visibility.Visible; 
     }; 
     splitter.DragDelta += (o, e) => 
     { 
      var pt = splitter.PointToScreen(Mouse.GetPosition(splitter)) - _ptForSplitterDrag 
       + splitter.PointToScreen(new Point()); 
      if (splitter.ResizeDirection == GridResizeDirection.Rows) 
      { 
       PopupWindowForSplitter.Top = pt.Y; 
      } 
      else 
      { 
       PopupWindowForSplitter.Left = pt.X; 
      } 
     }; 
     splitter.DragCompleted += (o, e) => 
     { 
      var initializeData = typeof(GridSplitter).GetMethod("InitializeData", BindingFlags.NonPublic | BindingFlags.Instance); 
      var moveSplitter = typeof(GridSplitter).GetMethod("MoveSplitter", BindingFlags.NonPublic | BindingFlags.Instance); 
      if (moveSplitter != null && initializeData != null) 
      { 
       initializeData.Invoke(splitter, new object[] { true }); 

       var pt = splitter.PointToScreen(Mouse.GetPosition(splitter)) - _ptForSplitterDrag; 
       if (splitter.ResizeDirection == GridResizeDirection.Rows) 
       { 
        moveSplitter.Invoke(splitter, new object[] { 0, pt.Y }); 
       } 
       else 
       { 
        moveSplitter.Invoke(splitter, new object[] { pt.X, 0 }); 
       } 
      } 
      PopupWindowForSplitter.Visibility = Visibility.Collapsed; 
     }; 

はたぶん、いくつかの問題があるため、私の下手な英語で私の説明であるが、私はコードがそれを説明するのに十分だと思います。

0

ソリューションは、以下のように、グリッド・スプリッタの内側に「Windowsフォーム」ラベルを追加し、それはそれの上に表示されるようにするDataGridViewを添加した後、プログラムでこれを行うには、次のようになります。

void AddLabelToSplitter() 
{ 
string template = 
    @" <ControlTemplate 
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
xmlns:mn='clr-namespace:MyNameSpace;assembly=MyAssembly' 
xmlns:wf='clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms' 
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' TargetType='{x:Type GridSplitter}'> 
      <mn:ExtendedWindowsFormsHost x:Name='Grid_Splitter_WindowsFormsHost' HorizontalAlignment='Stretch' VerticalAlignment='Stretch'> 
       <wf:Label Dock='Fill' BackColor='DarkGray'></wf:Label> 
      </mn:ExtendedWindowsFormsHost> 
     </ControlTemplate>"; 
Grid_Splitter.Template = (ControlTemplate)XamlReader.Parse(template); 
} 

それはスプリッタにマウスイベントを伝承、そのリンクの下からではなくExtendedWindowsFormsHostを使用していないだろうとして、通常のWindowsフォームホストが動作しません使用:

Keep Mouse Events bubbling from WindowsFormsHost on

関連する問題