Hi .
When i make cells of XAM Data grid editable, i am not able to drag the cells. please find my XAML code. When i turn AllowEdit="False". It is working properly.
How can i make cells editable and do Drag operation
<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" Drop="DragSource_Drop" DragOver="DragSource_DragOver" DragStart="DragSource_DragStart" DragChannels="channelModule"/>
</ig:DragDropManager.DragSource>
<ig:DragDropManager.DropTarget> <ig:DropTarget IsDropTarget="True" DropChannels="channelModule,ChannelA" 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> <Grid>
<Label Content="Component:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-1,0,0,0" /> <Label Content="{Binding Component.ComponentNumber}" Margin="79,0,187,0" VerticalAlignment="Top" FontWeight="Bold" Height="26"/> <Button Content="UnAssign" Command="{Binding UnAssignIOComponents}" HorizontalAlignment="Right" Width="75" Margin="0,0,0.333,2.333" Height="24" VerticalAlignment="Bottom" /> <cts:XamDataGrid x:Name="dgDeviceList" AllowDrop="True" GroupByAreaLocation="None" SelectedItems="{Binding SelectedElements, Mode=OneWayToSource}" DataSource="{Binding IOComponentsBindings}" BorderThickness="1" BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" ScrollingMode="Immediate" Margin="0,31,0.333,26.333" AssigningFieldLayoutToItem="xamDataGrid1_AssigningFieldLayoutToItem" InitializeRecordDirect="xamDataGrid1_InitializeRecordDirect"><cts:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings SelectionTypeRecord="Extended" AutoGenerateFields="False" ExpansionIndicatorDisplayMode="Never" /> </cts:XamDataGrid.FieldLayoutSettings>
<cts:XamDataGrid.FieldSettings>
<!--<igDP:FieldSettings CellClickAction="SelectRecord" AllowGroupBy="False" AllowHiding="Never" AllowEdit="False" AllowRecordFiltering="False" AllowSummaries="False" LabelTextAlignment="Left"/>--> <igDP:FieldSettings AllowEdit="True"/> </cts:XamDataGrid.FieldSettings> <cts:XamDataGrid.FieldLayouts>
<igDP:FieldLayout Key="IOcomponents"> <igDP:FieldLayout.SortedFields> <igDP:FieldSortDescription FieldName="IOSequenceNumber" Direction="Ascending" /> </igDP:FieldLayout.SortedFields> <igDP:Field Name="IOSequenceNumber" Label="Point" Width="0" Visibility="Collapsed"/> <igDP:Field Name="IOcomponentNumber" Label="Address" Width="Auto"> </igDP:Field> <igDP:Field Name="IODeviceName" Label="Tag" Width="Auto" > </igDP:Field> <igDP:Field Name="IODeviceDescription" Label="Description" Width="*" > </igDP:Field> <!--Converter="{StaticResource convert}" --> <igDP:Field Name="Components" Width="Auto" /> </igDP:FieldLayout>
<igDP:FieldLayout Key="child"> <igDP:Field Name="ComponentNumber" Label="Component Number" /> <igDP:Field Name="Description" Label="Description" Width="Auto" /> <igDP:FieldLayout.Settings> <igDP:FieldLayoutSettings LabelLocation="Hidden"/> </igDP:FieldLayout.Settings> </igDP:FieldLayout> </cts:XamDataGrid.FieldLayouts> </cts:XamDataGrid>
Hello Jerovsek,
The MouseDown event is not being handled in the CardPanel but in an element above it in the visual tree. This causes the DragDropManager not to work as you expected. What I could suggest you in this case is handling the PreviewMouseDown event. For this case you could use DragDrop control instead of DragDropManager (here you could find more information).
Please let me know if this helps you resolving your issue.
Hi Maria,
I have attached a sample, in it Drag is working as expected with cell edit mode to true. and mouse event in the card panel.
I was trying to do same styling but not working at my end. is there any thing i am missing.
Any help on this.
Since The page that has Xam datagrid is used as a drop source from another page as well as drag drop within the same page i need to go by dragdropmanager setting the drag channels.
Can you send me a sample on how to do drag drop with out drag drop manager and setting the record's edit mode to True.
I have looked into the attached project. It seems that everything works as expected in your xaml as it is the same as the one in the project. I suggest this behavior is caused by the operations in the EventHandler definitions. Could you provide me the code for them or a sample project where your issue occurs because I was not able to reproduce it?
Thank you.
I am checking if this is still an issue for you.
If you require any further assistance, please do not hesitate to ask.
I am just checking if you have any other questions on the matter.
Entering edit mode when a cell is selected and F2 is pressed is a default behavior for the XamDataGrid. I made a little modification to the project you sent and I set the CellClickAction to “SelectCell”. By doing this when user double click on a cell it enters edit mode and single click will allow the drag and drop functionality.
Please have a look at project and let me know if it helps you.
Thanks for your reply,
Is there any alternative to drag on the text or we just need to hover on the rectangle and do the drag drop.
Our next option would be when User clicks on the the cell the cell should be selected and if F2 is pressed then it should come to edit mode ,User edits text
and presses enter button then edit mode is cancelled, then i can do a drag drop. The problem i am facing here is as soon as i click on the cell, cell is into edit mode. How can i achieve this.
Hello,
Thank you for the sample. I investigated this issue further and it seems that the mouse click event is not handled in the textBox of the XamTextEditor but on a higher level of the visual tree. This is the reason why the drag and drop behavior could not be implemented when the cell is in edit mode. It is allowed when clicking on the active rectangle which is part of the CardPanel in the CellValuePresenter. I have tested this in the sample you have sent me before and the behavior is similar. The difference there is that active rectangle is bigger but if you tried to click on the text when it is in edit mode and drag and drop the item nothing happens.
Please feel free to let me know if you have other questions on the matter.
I have attached the sample. To reproduce the issue i have created the field layout.
To reproduce the Issue
1. Click on the Cell(Address1). Text is selected. Now try to drag the Text. Text is not dragged(A square Icon Appears).
2. What i noticed is when we start dragging on the border of the cell instead of the text then only drag is working.
Please find attached.