I'm using WPF 21.2. Using other topics on the forum and web I have been able to create an unbound field that presents a delete button for the record.
<Window x:Class="DeleteRecordFieldApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:igThemes="http://infragistics.com/Themes" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:DeleteRecordFieldApp" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Window.Resources> <ResourceDictionary> <DrawingImage x:Key="DeleteIcon"> <DrawingImage.Drawing> <GeometryDrawing> <GeometryDrawing.Geometry> <GeometryGroup> <LineGeometry StartPoint="10,10" EndPoint="90,90" /> <LineGeometry StartPoint="10,90" EndPoint="90,10" /> </GeometryGroup> </GeometryDrawing.Geometry> <GeometryDrawing.Pen> <Pen Thickness="20" Brush="Black" /> </GeometryDrawing.Pen> </GeometryDrawing> </DrawingImage.Drawing> </DrawingImage> <Style x:Key="DeleteButtonStyle" TargetType="{x:Type igDP:CellValuePresenter}" BasedOn="{x:Static igThemes:DataPresenterOffice2013.CellValuePresenter}"> <Setter Property="Visibility" Value="Hidden" /> <Setter Property="Opacity" Value="0.3" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Image Source="{StaticResource DeleteIcon}" HorizontalAlignment="Center" Width="10" Height="10" Stretch="Uniform" MouseLeftButtonDown="DeleteRecord" ToolTip="Remove this variable" /> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}}" Value="True" /> <Condition Binding="{Binding Path=IsAddRecord}" Value="False" /> </MultiDataTrigger.Conditions> <Setter Property="Visibility" Value="Visible" /> </MultiDataTrigger> <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True"> <Setter Property="Opacity" Value="1.0" /> </DataTrigger> </Style.Triggers> </Style> </ResourceDictionary> </Window.Resources> <Window.DataContext> <local:MyViewModel /> </Window.DataContext> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <igDP:XamDataGrid Grid.Row="0" Theme="Office2013" Margin="10" DataSource="{Binding MyData}" VerticalAlignment="Stretch"> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Settings> <igDP:FieldLayoutSettings AutoGenerateFields="False" AllowAddNew="True" AddNewRecordLocation="OnBottom" /> </igDP:FieldLayout.Settings> <igDP:TextField Label="Label" Name="Label" Width="*"> </igDP:TextField> <igDP:Field Name="deleteField" BindingType="Unbound" IsEnabledInAddRecord="False"> <igDP:Field.Settings> <igDP:FieldSettings AllowResize="False" AllowGroupBy="False" AllowRecordFiltering="False" AllowSummaries="False" CellWidth="20" LabelWidth="20" CellValuePresenterStyle="{StaticResource DeleteButtonStyle}" /> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> <igDP:XamDataGrid Grid.Row="1" Theme="Office2013" Margin="10" DataSource="{Binding MyData}" VerticalAlignment="Stretch"> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Settings> <igDP:FieldLayoutSettings AutoGenerateFields="False" AllowAddNew="True" AddNewRecordLocation="OnBottom" /> </igDP:FieldLayout.Settings> <igDP:TextField Label="Label" Name="Label" Width="*"> </igDP:TextField> <local:DeleteRecordField Name="DeleteRecord" /> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid> </Window>
I would like to abstract it all into a reusable class like you see in the second XamDataGrid. I've created the class and the Default.xaml, but I am getting something wrong and wondering if anyone can help out.DeleteRecordFieldApp.zip
Hello Walter,
It is worth noting that the delete functionality is already a built-in feature of the XamDataGrid – you simply need to set the XamDataGrid.FieldLayoutSettings.AllowDelete property to “True.” If you do this, then selecting records in the grid and pressing the Delete key will invoke the DeleteSelectedDataRecords command that you are currently invoking.
If you are looking for a built-in visualization for the delete key though, the best thing I can recommend is to either continue with what you are currently doing, or suggest a new product idea for that. You can suggest the new product idea here: https://ko.infragistics.com/community/ideas/i/ultimate-ui-for-wpf.
Please let me know if you have any other questions or concerns on this matter.
I appreciate your help. I have often wished for some sort of built-in thing to do this (feature request!).
I have been investigating into the behavior you are looking to achieve, and I have made a few changes to the sample project you have provided.
The largest change stems from the fact that you cannot style a XamDataGrid Field in the way that you are currently trying to. This is because the Field objects are not visual objects, and as such do not have templates or styles. For example, if you used a visual tree examination tool such as the third party tool Snoop or the one built-into later versions of Visual Studio, you would not find a Field object in the visual tree of your application.
Instead, I have moved the CellValuePresenterStyle that you have defined for the top grid into the App.xaml in the application and have defined a method that gets it in the DeleteRecordField class and applies it to its Settings.CellValuePresenterStyle. Rather than handling the MouseLeftButtonDown event on the App.xaml.cs, I have also defined a Behavior<Image> that handles this externally.
I am attaching a modified version of the sample project you have provided to demonstrate.
2627.DeleteRecordFieldApp.zip