0

我正在 WPF 中寻找一些可能性,如何通过在 WPF 数据网格或 Xceed 数据网格中拖动来显示行之间的水平线。

4

2 回答 2

0

您也可以使用这个拖放库:WPF 中的拖放(III)。你可以看到代码,他们使用装饰器在要放置的元素之间画一条线。

于 2013-02-07T19:37:40.807 回答
0

我认为你应该设置 RowStyle 属性,然后监听事件DragEnterDragLeave例如:

数据网格代码:

<DataGrid RowStyle="{DynamicResource DataGridRowStyle1}"/>

DataGrid这是已经具有两个触发器(forDragEnter和)的 wpf 行样式的副本DragLeave

<Style x:Key="DataGridRowStyle1" TargetType="{x:Type DataGridRow}">
        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
        <Setter Property="ValidationErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <TextBlock Foreground="Red" Margin="2,0,0,0" Text="!" VerticalAlignment="Center"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DataGridRow}">
                    <Border x:Name="DGR_Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                        <SelectiveScrollingGrid>
                            <SelectiveScrollingGrid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </SelectiveScrollingGrid.ColumnDefinitions>
                            <SelectiveScrollingGrid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </SelectiveScrollingGrid.RowDefinitions>
                            <DataGridCellsPresenter Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            <DataGridDetailsPresenter Grid.Column="1" Grid.Row="1" SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" Visibility="{TemplateBinding DetailsVisibility}"/>
                            <DataGridRowHeader Grid.RowSpan="2" SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical" Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"/>
                        </SelectiveScrollingGrid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <EventTrigger RoutedEvent="DragDrop.DragEnter"/>
                        <EventTrigger RoutedEvent="DragDrop.DragLeave"/>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

您唯一需要做的就是添加要显示的 or ,设置Lineon or ,然后在触发器中更改行的可见性值。希望这个答案可能对您有所帮助,并给您一个使其工作的想法,谢谢...RectangeVisibilityCollapsedHidden

于 2013-02-06T21:37:04.330 回答