Xceed DataGrid for WPF v7.2 Documentation
DataCell Class
Members  Example 


Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace : DataCell Class
Specialization of the Cell class that represents a cell contained in a DataRow.
Syntax
'Declaration
 
<TemplatePartAttribute(Name="PART_CellContentPresenter", Type=System.Windows.Controls.ContentPresenter)>
<DefaultPropertyAttribute("Content")>
<ContentPropertyAttribute("Content")>
<LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)>
<StyleTypedPropertyAttribute(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)>
<XmlLangPropertyAttribute("Language")>
<UsableDuringInitializationAttribute(True)>
<RuntimeNamePropertyAttribute("Name")>
<UidPropertyAttribute("Uid")>
<TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider)>
<NameScopePropertyAttribute("NameScope", System.Windows.NameScope)>
Public Class DataCell 
   Inherits Cell
'Usage
 
Dim instance As DataCell
[TemplatePart(Name="PART_CellContentPresenter", Type=System.Windows.Controls.ContentPresenter)]
[DefaultProperty("Content")]
[ContentProperty("Content")]
[Localizability(LocalizationCategory.None, Readability=Readability.Unreadable)]
[StyleTypedProperty(Property="FocusVisualStyle", StyleTargetType=System.Windows.Controls.Control)]
[XmlLangProperty("Language")]
[UsableDuringInitialization(true)]
[RuntimeNameProperty("Name")]
[UidProperty("Uid")]
[TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]
[NameScopeProperty("NameScope", System.Windows.NameScope)]
public class DataCell : Cell 
Example
All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.
The following example demonstrates how to change the foreground and background of the current cell.The following example demonstrates how to provide, through a style, a new ControlTemplate for the DataCells that will display the cells as buttons.The following example demonstrates how to provide a new style that will change the foreground color of a cell when its value fails the validation process. It uses the ShippingCostValidationRule custom validation rule defined in the previous example.
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
  <Grid.Resources>

    <Style TargetType="{x:Type xcdg:DataCell}">
      <Setter Property="CurrentForeground">
        <Setter.Value>
          <SolidColorBrush Color="Yellow"/>
        </Setter.Value>
        </Setter>
          <Setter Property="CurrentBackground">
            <Setter.Value>
          <SolidColorBrush Color="Orange"/>
        </Setter.Value>
      </Setter>
    </Style>
    <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                    Source="{Binding Source={x:Static Application.Current},
                                                      Path=Orders}"/>
   </Grid.Resources>
   <xcdg:DataGridControl x:Name="OrdersGrid"
                         ItemsSource="{Binding Source={StaticResource cvs_orders}}"/>
</Grid>
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
  <Grid.Resources>
    <Style TargetType="{x:Type xcdg:DataCell}">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type xcdg:DataCell}">
            <Button>
              <Button.Content>
                <ContentPresenter/>
              </Button.Content>
            </Button>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>
    <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                    Source="{Binding Source={x:Static Application.Current},
                                                      Path=Orders}"/>
   </Grid.Resources>
   <xcdg:DataGridControl x:Name="OrdersGrid"
                         ItemsSource="{Binding Source={StaticResource cvs_orders}}"/>
</Grid>
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
      xmlns:local="clr-namespace:Xceed.Wpf.Documentation"> 
  <Grid.Resources>
    <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                    Source="{Binding Source={x:Static Application.Current},
                                                      Path=Orders}"/>
   </Grid.Resources>
   <xcdg:DataGridControl x:Name="OrdersGrid"
                         ItemsSource="{Binding Source={StaticResource cvs_orders}}">
      <xcdg:DataGridControl.Resources>

        <Style x:Key="cell_error" TargetType="{x:Type xcdg:DataCell}">
           <Setter Property="Foreground" Value="Red"/>
        </Style>
      </xcdg:DataGridControl.Resources>      

      <xcdg:DataGridControl.Columns>
        <xcdg:Column FieldName="Freight" CellErrorStyle="{StaticResource cell_error}">
           <xcdg:Column.CellValidationRules>
              <local:ShippingCostValidationRule/>
           </xcdg:Column.CellValidationRules>
        </xcdg:Column>
      </xcdg:DataGridControl.Columns>
   </xcdg:DataGridControl>
</Grid>
Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  System.Windows.Controls.Control
                     System.Windows.Controls.ContentControl
                        Xceed.Wpf.DataGrid.Cell
                           Xceed.Wpf.DataGrid.DataCell
                              Xceed.Wpf.DataGrid.InsertionCell

Requirements

Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DataCell Members
Xceed.Wpf.DataGrid Namespace