Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1385
XamDataGrid delete row field in an inherited class
posted

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