Hi team,
I have the implementation of Drag & Drop b/w two XAMDatagrids as below in xaml
<UserControl.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="BackgroundHover" Value="Transparent"/> <Setter Property="BorderHoverBrush" Value="Transparent"/> <!--<Setter Property="BackgroundActive"> <Setter.Value> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="#FF85A2B2"/> <GradientStop Offset="1.1" Color="#00FFFFFF"/> </LinearGradientBrush> </Setter.Value> </Setter>--> <Setter Property="BorderActiveBrush" Value="#00151C55"/> <Setter Property="BackgroundSelected"> <Setter.Value> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="#FFCAEBFF"/> <GradientStop Offset="1.1" Color="#00FFFFFF"/> <GradientStop Color="#83CAEBFF" Offset="1"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="BorderSelectedBrush" Value="#FF666666"/> <Setter Property="BackgroundFieldSelected"> <Setter.Value> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="#FFDDDDDD"/> <GradientStop Offset="1.1" Color="#00FFFFFF"/> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="BorderFieldSelectedBrush" Value="#FF666666"/> <Setter Property="BackgroundPrimary" Value="#7FE9E9E9"/> <Setter Property="BorderPrimaryBrush" Value="#FFE9E9E9"/> <Setter Property="ForegroundStyle"> <Setter.Value> <Style/> </Setter.Value> </Setter> <Setter Property="ForegroundActiveStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}" /> <Setter Property="ForegroundAlternateStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}" /> <Setter Property="ForegroundPrimaryStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}" /> <Setter Property="ForegroundSelectedStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}" /> <Setter Property="ForegroundFieldSelectedStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}" /> <Setter Property="ForegroundHoverStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}" /> <Setter Property="CornerRadius" Value="0"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Padding" Value="2,0,0,0"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <!-- AS 5/23/07 BR23120 --> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <igWindows:CardPanel MouseDown="CardPanel_MouseDown" >
<ig:DragDropManager.DragSource> <ig:DragSource IsDraggable="True" DragChannels="ChannelA" Drop="DragSource_Drop" DragOver="DragSource_DragOver" DragStart="DragSource_DragStart" /> </ig:DragDropManager.DragSource>
<ig:DragDropManager.DropTarget> <ig:DropTarget DropTargetMarkerBrush="Red" /> </ig:DragDropManager.DropTarget>
<!-- [JM 06-06-07] This element is not being used so I am commenting it out. Its Visibility property is initialized to Collapsed and the IsSelected trigger below has commented out the line that sets the Visibility to Visible. Checked with Grant on this and he feels it is left over from early styling efforts and can be removed. --> <!--<Rectangle x:Name="LeftBorder" Fill="#FFBBBBBB" Width="1" Margin="0,1,0,0" HorizontalAlignment="Left" VerticalAlignment="Stretch" Visibility="Collapsed" />--> <Border x:Name="MainBorder" CornerRadius="{TemplateBinding CornerRadius}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"/> <Rectangle x:Name="Active" Fill="{TemplateBinding BackgroundActive}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" SnapsToDevicePixels="True" Opacity="1" Visibility="Collapsed" StrokeThickness="1" Stroke="{TemplateBinding BorderActiveBrush}"/> <ContentPresenter x:Name="PART_EditorSite" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" Style="{TemplateBinding ForegroundStyle}" >
</ContentPresenter> </igWindows:CardPanel> <ControlTemplate.Triggers> <!-- HighlightAsPrimary --> <Trigger Property="HighlightAsPrimary" Value="true"> <Setter Property="Background" Value="{Binding Path=BackgroundPrimary, RelativeSource={RelativeSource Self}}"/> <Setter Property="BorderBrush" Value="{Binding Path=BorderPrimaryBrush, RelativeSource={RelativeSource Self}}"/> <Setter TargetName="PART_EditorSite" Property="Style" Value="{Binding Path=ForegroundPrimaryStyle, RelativeSource={RelativeSource TemplatedParent}}"/> </Trigger> <!-- IsFieldSelected --> <Trigger Property="IsFieldSelected" Value="true"> <Setter Property="Background" Value="{Binding Path=BackgroundFieldSelected, RelativeSource={RelativeSource Self}}"/> <Setter Property="BorderBrush" Value="{Binding Path=BorderFieldSelectedBrush, RelativeSource={RelativeSource Self}}"/> <Setter TargetName="PART_EditorSite" Property="Style" Value="{Binding Path=ForegroundFieldSelectedStyle, RelativeSource={RelativeSource TemplatedParent}}"/> </Trigger> <!-- IsSelected --> <Trigger Property="IsSelected" Value="true"> <Setter Property="Background" Value="{Binding Path=BackgroundSelected, RelativeSource={RelativeSource Self}}"/> <Setter Property="BorderBrush" Value="{Binding Path=BorderSelectedBrush, RelativeSource={RelativeSource Self}}"/> <Setter TargetName="PART_EditorSite" Property="Style" Value="{Binding Path=ForegroundSelectedStyle, RelativeSource={RelativeSource TemplatedParent}}"/> <!--<Setter Property="Visibility" Value="Visible" TargetName="LeftBorder" />--> </Trigger> <!-- IsActive --> <Trigger Property="IsActive" Value="true"> <Setter TargetName="PART_EditorSite" Property="Style" Value="{Binding Path=ForegroundActiveStyle, RelativeSource={RelativeSource TemplatedParent}}"/> <Setter Property="Visibility" TargetName="Active" Value="Visible"/> </Trigger> <!-- IsMouseOver --> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True"/> <Condition Property="IsSelected" Value="False"/> <Condition Property="IsFieldSelected" Value="False"/> </MultiTrigger.Conditions> <Setter Property="Background" Value="{Binding Path=BackgroundHover, RelativeSource={RelativeSource Self}}"/> <Setter Property="BorderBrush" Value="{Binding Path=BorderHoverBrush, RelativeSource={RelativeSource Self}}"/> <Setter TargetName="PART_EditorSite" Property="Style" Value="{Binding Path=ForegroundHoverStyle, RelativeSource={RelativeSource TemplatedParent}}"/> </MultiTrigger> <!-- Field.IsFixedStateChanging JM 01-22-09 NA 9.1 FixedFields --> <DataTrigger Binding="{Binding Path=Field.IsFixedStateChanging, RelativeSource={RelativeSource Self}}" Value="True"> <Setter Property="Background" Value="#AA8DBAEB"/> <Setter Property="BorderBrush" Value="#AA8DBAEB"/> </DataTrigger> <!--SSP 5/27/09 NAS9.2 IDataErrorInfo Support--> <Trigger Property="IsDataErrorTemplateActive" Value="true"> <Setter TargetName="PART_EditorSite" Property="ContentTemplate" Value="{DynamicResource {x:Static igDP:DataPresenterBase.DataErrorContentTemplateKey}}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <!-- DRCA Foreground Hover Trigger-->
<!-- JJD 4/30/09 - TFS17157 use new IsRecordSelected property --> <Trigger Property="IsRecordSelected" Value="True"> <Setter Property="ForegroundStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}" /> </Trigger>
<!-- DRCA Foreground Selected Trigger--> <!-- JJD 4/30/09 - TFS17157 use new IsMouseOverRecord property --> <Trigger Property="IsMouseOverRecord" Value="True"> <Setter Property="ForegroundStyle" Value="{DynamicResource {ComponentResourceKey {x:Type igDP:XamDataGrid}, GrayForegroundStyle}}" /> </Trigger>
</Style.Triggers> </Style>
</usercontrol.resources>
My Events in the Code behind are as follws.
DataRecordPresenter dp; DataRecordPresenter dragOver; private void DragSource_DragStart(object sender, Infragistics.DragDrop.DragDropStartEventArgs e) {
dp = Utilities.GetAncestorFromType(e.DragSource as DependencyObject, typeof(DataRecordPresenter), false) as DataRecordPresenter; }
private void DragSource_Drop(object sender, Infragistics.DragDrop.DropEventArgs e) { dragOver = Utilities.GetAncestorFromType(e.DropTarget as DependencyObject, typeof(DataRecordPresenter), false) as DataRecordPresenter;
ComponentList targetElement = dragOver.DataRecord.DataItem as ComponentList; ComponentBase sourceElement = dp.DataRecord.DataItem as ComponentBase; viewmodel vm = dragOver.DataPresenter.DataContext as viewmodel ; // My Business logic continues
}
int overIndex; private void DragSource_DragOver(object sender, Infragistics.DragDrop.DragDropMoveEventArgs e) {
dragOver = Utilities.GetAncestorFromType(e.DropTarget as DependencyObject, typeof(DataRecordPresenter), false) as DataRecordPresenter; overIndex = dragOver.Record.VisibleIndex;
My requirement is i should highlight entire row when i start dragging.
Hello,
Thank you for your post. I have been looking into the functionality that you are trying to achieve and I can suggest using the DataRecordPresenter as DragSource and DropTarget. By doing so you will have the Record highlighted when you drag another record over it. I have created a sample application for you, that demonstrates how you can implement the approach I have mentioned.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
I am just checking if you require any further assistance on the matter.
Hi krasimir,
The Solution works fine but i have an another requirement here.
Based on the Id in the collection i am setting the back ground of my child records as below
<cts:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:DataRecordPresenter}"> <Setter Property="Background"> <Setter.Value> <SolidColorBrush Color="{Binding Path=DataItem, Converter={StaticResource bgColorConverter}}" Opacity="0.3"/> </Setter.Value> </Setter> </Style> <!--<Style TargetType="{x:Type igDP:DataRecordCellArea}"> <EventSetter Event="MouseDown" Handler="StartDragging"/> </Style>--> </cts:XamDataGrid.Resources>
I have a converter class to change the back ground of child record in the hierachial grid which i am setting it to red.
When i drag that record i need to change the back ground of that particular record to transparent.
I have tried some of the below code
DataRecordPresenter dragsource = Utilities.GetAncestorFromType(e.DragSource as DependencyObject, typeof(DataRecordPresenter), false) as DataRecordPresenter
int startIndex = dragsource .Record.VisibleIndex;
CellValuePresenter.FromCell((dgDeviceList2.Records[startIndex] as DataRecord).Cells[1]).Background = Brushes.Yellow; DataRecordPresenter.FromRecord(dgDeviceList2.Records[1] as DataRecord).Background = Brushes.Yellow;
The problem here is it is changing the parent's background but not the child or the dragged item's back ground.
How should i go with this ?.
Thank you for your email. I am very glad that you have managed to solve the issue that you were having. Please let me know if you need any further assistance on the matter.
Below Code worked.
dragsource.background = Brushes.White, has done what i wanted.