0

GridSplitterの可視性に関して問題があります。

これでは、WinformDataGridViewをホストしているものは何でも。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>
4

6 に答える 6

1

通常、GridSplitterを独自のグリッドセルに配置するか、マージンを介してコントロールがオーバーラップできないようにする必要があります。しかし、それがここであなたに正確に当てはまるかどうかはわかりません。こちらもご覧ください

于 2009-04-06T06:44:25.930 に答える
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;
        };

英語が下手なので、説明に問題があるかもしれませんが、コードはそれを説明するのに十分だと思います。

于 2012-05-18T07:42:34.223 に答える
0

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

詳細については、「 WPFでのMicrosoft Win32ウィンドウのホスト(出力動作の顕著な違いの小見出し)」を参照してください。

于 2009-04-06T12:24:38.390 に答える
0

WPF ネイティブの DataGrid コントロールを使用してみてください。購入できる商用のサードパーティ製コントロールがいくつかあります。または、Microsoft が提供するコントロールを確認することもできます (現在はまだ CTP にあります)。

于 2009-04-06T08:42:35.410 に答える
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);
}

通常の Windows フォーム ホストを使用すると、マウス イベントがスプリッターに渡されないため、機能しません。そのため、代わりに以下のリンクから ExtendedWindowsFormsHost を使用してください。

WindowsFormsHost からのマウス イベントのバブリングを維持する

于 2015-06-01T08:25:26.450 に答える
0

あなたの状況では、最も簡単な修正は、GirdSplitter を Button のある行に移動することです。

<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>

余白を調整して、ボタンとグリッド スプリッターの間にある程度のスペースがあることを確認します。

于 2009-04-06T18:59:50.780 に答える