"Value does not fall within the expected range." exception when drop targets are in a hidden tab

Sep 11, 2009 at 4:38 PM

Hi Kevin,

Firstly, thanks for the latest release, we’re making use of it now.

Unfortunately I’ve come across a problem when using drag and drop with a TabControl (it’s not just the latest release it also occurs in the previous build we’ve used).

If the drop targets are contained within a TabItem of a TabControl and that TabItem is not the correctly active tab, we receive a “Value does not fall within the expected range.” exception.

To help with debugging, below is the XAML of an updated sucDragDrop0.xaml which hosts the drop targets within a TabControl.

<UserControl x:Class="SL_Drag_Drop.sucDragDrop0"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    >
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>


        <StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="10">
            <TextBlock Text="Default behaviour" 
                       FontSize="14"
                       HorizontalAlignment="Left" VerticalAlignment="Top"
                       ></TextBlock>
            <TextBlock TextWrapping="Wrap" Margin="0,10,0,0" >
                A bunch of DropTargets on the left, a bunch of DragSources (on DropTargets) 
                on the right.  Ghosts are added, animations are on.</TextBlock>
        </StackPanel>

        <controls:TabControl  Grid.Row="1" Grid.Column="0">
            <controls:TabItem Header="The targets">
                <Grid>
                    <StackPanel x:Name="PanelDropTargets" Orientation="Vertical" HorizontalAlignment="Center" />
                </Grid>
            </controls:TabItem>
            <controls:TabItem Header="Empty Tab">
                <Grid/>
            </controls:TabItem>
        </controls:TabControl>


        <StackPanel x:Name="PanelDragSources" Orientation="Vertical" HorizontalAlignment="Center"
                           Grid.Row="1" Grid.Column="1">
        </StackPanel>

     </Grid>
</UserControl>

If “The targets” tab is selected, everything works fine when dragging one of the sources, but if the “Empty Tab” is selected we get the exception as soon as dragging begins. Below is the stack trace.

System.ArgumentException: Value does not fall within the expected range.
   at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
   at MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)
   at MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element, UIElement visual)
   at System.Windows.UIElement.TransformToVisual(UIElement visual)
   at SL_Drag_Drop_BaseClasses.DragSource.CheckIfIAmInDropTarget()

As you’ll see the exception is occurring when the drag source is trying to establish if it’s in a drop target

I’ve made some initial attempts at finding a solution, along the lines of checking if the drop target is in a hidden tab, but I can’t find any property of the drop target that indicates this, for instance its “Visibility” property is still “Visible”. I’ve thought about walking the parent hierarchy to see if the drop target is within a TabItem, which isn’t the current active tab within the TabControl, but that seems rather a hack, and I would hope there to be a more elegant solution.

Any ideas?

Regards,

Jim.

Coordinator
Sep 14, 2009 at 2:32 PM

Hello Jim,

 

I will try to figure out what's going on here as soon as I can (haven't tested it with the TabControl tbh), but I do think you're on the right track when you're saying it has something to do with establishing if a drag source is in a drop target, and I would indeed suggest something along the lines of walking through the visualtree.  However, I'll see if I can find out exactly what's going on, maybe I'll find a better solution :-)

I'll get back to you!

Regards,
Kev. 

Dec 15, 2009 at 9:55 AM
Edited Dec 15, 2009 at 11:03 AM

HI,

Thanks for “drag and Drop” functionality in SL.

I have implemented the drag and drop functionality in the grids but I am getting exception (Value does not fall within the expected range) in 679 line of “DragSource” class.

Can anyone faced this problem and found the fix for this.

Here is my code:

<UserControl x:Class="DragAndDropTest.GLTransactionDragAndDrop"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:dragdrop="clr-namespace:SL_Drag_Drop_BaseClasses;assembly=SL_Drag_Drop_BaseClasses"

    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"

   >

    <Grid x:Name="LayoutRoot">

        <Grid.ColumnDefinitions>

            <ColumnDefinition></ColumnDefinition>

            <ColumnDefinition></ColumnDefinition>

        </Grid.ColumnDefinitions>

 

        <data:DataGrid x:Name="grdBankStatement" AutoGenerateColumns="False" Grid.Column="0" Margin="20">

            <data:DataGrid.Columns>

                <data:DataGridTextColumn Binding="{Binding TransactionName}" IsReadOnly="True" Header="Transaction"></data:DataGridTextColumn>

                <data:DataGridTextColumn Binding="{Binding Amount}" IsReadOnly="True" Header="Amount"></data:DataGridTextColumn>

                <data:DataGridTextColumn Binding="{Binding Date}" IsReadOnly="True" Header="Date"></data:DataGridTextColumn>

                <data:DataGridTemplateColumn Header="Date">

                    <data:DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <dragdrop:DropTarget ShowHover="False">

                                <dragdrop:DropTarget.Content>

                                    <dragdrop:DragSource AllDropTargetsValid="True"

                                         ShowReturnToOriginalPositionAnimation="False"

                                         DropMode="ReturnDragSource" DragHandleMode="FullDragSource"

                                         Tag="{Binding TransactionName}">

                                        <TextBlock Text="Drag" ></TextBlock>

                                    </dragdrop:DragSource>

                                </dragdrop:DropTarget.Content>

                                <dragdrop:DropTarget.Ghost>

                                    <TextBlock Text="Drag" ></TextBlock>

                                </dragdrop:DropTarget.Ghost>

                            </dragdrop:DropTarget>

                        </DataTemplate>

                    </data:DataGridTemplateColumn.CellTemplate>

                </data:DataGridTemplateColumn>

 

            </data:DataGrid.Columns>

 

        </data:DataGrid>

 

        <data:DataGrid x:Name="grdGLTransactions" AutoGenerateColumns="False" Grid.Column="1" Margin="20">

            <data:DataGrid.Columns>

                <data:DataGridTextColumn Binding="{Binding Description}" IsReadOnly="True" Header="Desc"></data:DataGridTextColumn>

                <data:DataGridTextColumn Binding="{Binding Amount}" IsReadOnly="True" Header="Amount"></data:DataGridTextColumn>

                <data:DataGridTextColumn Binding="{Binding Date}" IsReadOnly="True" Header="Date"></data:DataGridTextColumn>

                <data:DataGridTextColumn Binding="{Binding SelectedBankStatement,Mode=TwoWay}" Header="Selected Bank Trans"></data:DataGridTextColumn>

                <data:DataGridTemplateColumn Header="">

                    <data:DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <dragdrop:DropTarget Width="160" Height="75" HorizontalAlignment="Center"

                                 DragSourceDropped="DropTarget_DragSourceDropped"

                                 Grid.Row="1" VerticalAlignment="Top" Tag="{Binding Id}" >

                                <dragdrop:DropTarget.DropBorderBrush>

                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

                                        <GradientStop Color="#FFD83F00" Offset="0"/>

                                        <GradientStop Color="#FFF65E00" Offset="1"/>

                                    </LinearGradientBrush>

                                </dragdrop:DropTarget.DropBorderBrush>

                                <dragdrop:DropTarget.Content>

                                    <dragdrop:DragSource DraggingEnabled="False">

 

                                        <Image Source="Images/box_open.png" HorizontalAlignment="Center"

                               VerticalAlignment="Center" Width="128" Height="128">

                                        </Image>

                                        <!--<TextBlock Text="Drop"></TextBlock>-->

 

                                    </dragdrop:DragSource>

                                </dragdrop:DropTarget.Content>

                            </dragdrop:DropTarget>

                        </DataTemplate>

                    </data:DataGridTemplateColumn.CellTemplate>

                </data:DataGridTemplateColumn>

 

            </data:DataGrid.Columns>

 

        </data:DataGrid>

    </Grid>

</UserControl>

 Regards,

Hareen.

Feb 25, 2010 at 4:25 PM

I did faced the problem but still waiting for a solution