Cant remove cell border

 <syncfusion:SfDataGrid
     AllowEditing="False"
     AllowGrouping="False"
     AllowSorting="False"
     AutoGenerateColumns="False"
     BorderThickness="0"
     ColumnSizer="Auto"
     CurrentCellBorderThickness="0,0,0,0"
     FontSize="15"
     HeaderRowHeight="0"
     NavigationMode="Row"
     RowHeight="25"
     RowSelectionBrush="{StaticResource AccentBrush}"
     ShowGroupDropArea="False">
     <syncfusion:SfDataGrid.Resources>
         <Style
            
             TargetType="syncfusion:GridCell">
             <Setter Property="BorderThickness" Value="0"/>
         </Style>
    <syncfusion:SfDataGrid.Columns>
        <syncfusion:GridTextColumn
            Width="50"
            HeaderText="ID"
            MappingName="ID/>
        <syncfusion:GridTextColumn
            Width="40"
            HeaderText="Info"
            MappingName="Info"/>
        <syncfusion:GridTextColumn
            ColumnSizer="Star"
            HeaderText="Text"
            MappingName="Text"/>
    </syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>


I had this code working fine, but after update to latest version of wpf and using .net8, its no longer hiding cell border, Infact it has no effect of using syncfusion:GridCell style.


Using WPF version 26.1.35


4 Replies

SG Santhosh Govindasamy Syncfusion Team September 19, 2024 12:52 PM UTC

Hi John,

Thank you for reaching out.

Based on the information and code snippet provided, it appears that you are trying to update the BorderThickness of grid cells in the resources. However, after updating to the latest version of WPF and using .NET 8, you are experiencing an issue where the style for syncfusion:GridCell in SfDataGrid is no longer hiding the cell borders. It seems that the style is not being applied correctly in the updated version.
 

To investigate further, we have created a simple sample to replicate the reported scenario in the mentioned version. In our testing, the BorderThickness was properly applied. For your reference, we have attached the sample and video reference, where the border thickness is correctly applied.
 

To proceed further, could you please provide details about any other customizations you have made to the DataGrid? This information will be helpful in understanding and addressing the problem.
 

Thank you for your cooperation.

Regards,
Santhosh.G


Attachment: SfDataGrid_Net__6daef80e.zip


JO John September 19, 2024 05:48 PM UTC

I dont know, it doesn't work for me. I tried this


CellStyle="{StaticResource customCellStyle}" in sfdatagrid


and this in resources


 <Style TargetType="syncfusion:GridCell" x:Key="customCellStyle">
     <Setter Property="Background" Value="Bisque" />
 </Style>


and after run, I get this error,


System.InvalidOperationException: ''GridCell' TargetType does not match type of element 'GridCell'.'


System.InvalidOperationException

  HResult=0x80131509

  Message='GridCell' TargetType does not match type of element 'GridCell'.

  Source=PresentationFramework

  StackTrace:

   at System.Windows.Style.CheckTargetType(Object element) in System.Windows\Style.cs:line 394

   at System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) in System.Windows\FrameworkElement.cs:line 1486

   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) in System.Windows\FrameworkElement.cs:line 2424

   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)

   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)

   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)

   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)

   at Syncfusion.UI.Xaml.Grid.Cells.GridVirtualizingCellRendererBase`2.SetCellStyle(DataColumnBase dataColumn, Object record)

   at Syncfusion.UI.Xaml.Grid.Cells.GridVirtualizingCellRendererBase`2.InitializeCellStyle(DataColumnBase dataColumn, Object record)

   at Syncfusion.UI.Xaml.Grid.Cells.GridVirtualizingCellRendererBase`2.OnUpdateStyleInfo(DataColumnBase dataColumn, Object dataContext)

   at Syncfusion.UI.Xaml.Grid.Cells.GridCellRendererBase.UpdateCellStyle(DataColumnBase dataColumn, Object dataContext)

   at Syncfusion.UI.Xaml.Grid.DataColumn.UpdateCellStyle(Object dataContext)

   at Syncfusion.UI.Xaml.Grid.OrientedCellsPanel.EnsureItems(Size availableSize)

   at Syncfusion.UI.Xaml.Grid.OrientedCellsPanel.MeasureOverride(Size availableSize)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in System.Windows\FrameworkElement.cs:line 3293

   at System.Windows.UIElement.Measure(Size availableSize)

   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) in MS.Internal\Helper.cs:line 320

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in System.Windows\FrameworkElement.cs:line 3293

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Border.MeasureOverride(Size constraint) in System.Windows.Controls\Border.cs:line 339

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in System.Windows\FrameworkElement.cs:line 3293

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Grid.MeasureOverride(Size constraint) in System.Windows.Controls\Grid.cs:line 984

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in System.Windows\FrameworkElement.cs:line 3293

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.Controls.Control.MeasureOverride(Size constraint) in System.Windows.Controls\Control.cs:line 519

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in System.Windows\FrameworkElement.cs:line 3293

   at System.Windows.UIElement.Measure(Size availableSize)

   at Syncfusion.UI.Xaml.Grid.DataRowBase.MeasureElement(Size size)

   at Syncfusion.UI.Xaml.Grid.VisualContainer.MeasureRows()

   at Syncfusion.UI.Xaml.Grid.VisualContainer.MeasureOverride(Size constraint)

   at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in System.Windows\FrameworkElement.cs:line 3293

   at System.Windows.UIElement.Measure(Size availableSize)

   at System.Windows.ContextLayoutManager.UpdateLayout()

   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)

   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()

   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)

   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)

   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

   at System.Windows.Threading.DispatcherOperation.InvokeImpl()

   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

--- End of stack trace from previous location ---

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Windows.Threading.DispatcherOperation.Invoke()

   at System.Windows.Threading.Dispatcher.ProcessQueue()

   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)

   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

 

...........REMOVED




JO John September 19, 2024 06:34 PM UTC

Found the solution

I use

xmlns:grid="clr-namespace:Syncfusion.UI.Xaml.Grid;assembly=Syncfusion.SfGrid.WPF"

and

 <Style TargetType="grid:GridCell"/>




SG Santhosh Govindasamy Syncfusion Team September 20, 2024 01:17 PM UTC

Hi John,

Thank you for your response.


Based on your last update, it seems that you encountered the following error:


System.InvalidOperationException: ''GridCell' TargetType does not match type of element 'GridCell'.'

 



You mentioned that you resolved this issue by using the correct namespace reference:

xmlns:grid="clr-namespace:Syncfusion.UI.Xaml.Grid;assembly=Syncfusion.SfGrid.WPF"

<Style TargetType="grid:GridCell"/>

 

 


This error occurs due to an ambiguous type reference, as the TargetType in the style was not matching the correct GridCell type. It seems like the issue has been resolved on your end by adjusting the namespace and TargetType in the Style declaration, which is appreciated.

For further reference or additional guidance on handling such type reference issues, please check the knowledge base article linked below.

https://support.syncfusion.com/kb/article/5288/how-to-resolve-ambiguous-type-reference-exception-in-wpf-griddatacontrol

If you have any more questions or need further assistance, feel free to reach out.

Regards,
Santhosh.G


Loader.
Up arrow icon