0

I have a DataGrid and has implemented with drag drop features Now when I try to scroll, it does not work simply display a Nude sign. I subscribe ScrollBar.Scroll, but inside it, I can't get the info how to scroll, I do not know if I should scroll up or down. I must have missed something. Pls help. thanks

<toolkit:DataGrid x:Name="dg"                                                                  
    Style="{StaticResource DataGridStyle}"
    RowDetailsVisibilityMode="VisibleWhenSelected" 
    ItemsSource="{Binding Relations}"                           
    SelectionUnit="FullRow" 
    SelectedItem="{Binding ListSelection}" IsReadOnly="True" 
    VerticalScrollBarVisibility="Auto" 
    HorizontalScrollBarVisibility="Auto"
    MouseDoubleClick="dg_MouseDoubleClick"
    PreviewKeyDown="DgPreviewKeyDown"
    PreviewMouseWheel="DgPreviewMouseWheel"
    PreviewMouseLeftButtonDown="DataGridPreviewMouseLeftButtonDown"
    PreviewMouseMove="DataGridMouseMove"
    Drop="DataGridDrop" 
    DragEnter="DataGridDragEnter"
    ScrollBar.Scroll="DgScroll">
    <toolkit:DataGrid.Columns>
        <toolkit:DataGridTextColumn Header="Symbol" Binding="{Binding Relation}" MinWidth="310">
            <toolkit:DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="TextWrapping" Value="Wrap" />
                </Style>
            </toolkit:DataGridTextColumn.ElementStyle>
        </toolkit:DataGridTextColumn>
        <toolkit:DataGridTextColumn Header="Description" Width="*" MinWidth="300" Binding="{Binding Description}">
            <toolkit:DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="TextWrapping" Value="Wrap" />
                </Style>
            </toolkit:DataGridTextColumn.ElementStyle>
        </toolkit:DataGridTextColumn>
    </toolkit:DataGrid.Columns>
</toolkit:DataGrid>

private void DgScroll(object sender, ScrollEventArgs e)
{
    var viewer = DragDropHelper.GetDescendantByType(dg, typeof(ScrollViewer)) as ScrollViewer;
    if (viewer == null) return;

    var newVal = e.NewValue;  //How I can know scroll up or down???
    viewer.ScrollToVerticalOffset(viewer.VerticalOffset + 30)       
}
LPL
  • 16,827
  • 6
  • 51
  • 95
toosensitive
  • 2,335
  • 7
  • 46
  • 88
  • I did not find a solution from http://stackoverflow.com/questions/4124877/wpf-datagrid-cant-use-mouse-to-scroll-because-of-drag-drop – toosensitive Oct 16 '13 at 21:15
  • I tried a separate scrollviewer but that causes new problem - slow performance. http://stackoverflow.com/questions/11127511/slow-performance-with-wpf-datagrid-and-scrollviewer?rq=1 – toosensitive Oct 16 '13 at 21:16
  • Take a look at the answer of this question: http://stackoverflow.com/questions/10733581/scrolling-while-dragging-and-dropping-wpf – Daniel Rose Apr 25 '14 at 10:37

1 Answers1

1

Okay, you can use of of style to address your problem. EventHandler OnRepeatButtonClicked try to get visual parent item (scrollbar) and store the current value of scoll. and in the ValueChangedEventHandler you can check whether your new scroll value is getting increase (downwards) or decrease (upwards). Keep updating your current value every time you scroll. Reference

 <Style x:Key="VerticalScrollBarStyle" TargetType="ScrollBar">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ScrollBar">
                    <Grid x:Name="VerticalRoot">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Disabled"/>
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Rectangle RadiusX="8" RadiusY="9" Stroke="#0C848D8D"  Grid.Row="1" Grid.RowSpan="3" >
                            <Rectangle.Fill>
                                <LinearGradientBrush EndPoint="0.5,0.5" StartPoint="0,0.5">
                                    <GradientStop Color="#33000000" Offset="0.061"/>
                                    <GradientStop Color="#19EEFEFF" Offset="0.788"/>
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <RepeatButton x:Name="VerticalLargeDecrease" Opacity="0"  Grid.Row="1" Click="OnRepeatButtonClicked"/>
                        <Thumb x:Name="VerticalThumb"  Grid.Row="2"  VerticalAlignment="Center" Style="{StaticResource VerticalScrollbarThumbStyle}"/>
                        <RepeatButton x:Name="VerticalLargeIncrease" Opacity="0" Grid.Row="3" Click="OnRepeatButtonClicked"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Orientation" Value="Vertical"/>
    </Style>
saurabh.mridul
  • 177
  • 1
  • 11