Problem with inheriting from SfDataGrid control - .NET 6 Visual Studio 2022

Hello,

I have a problem with the SfDataGrid control. First of all Visual Studio is not able to generate a template by clicking in the context menu on the control: edit template -> edit copy. VS does not do anything. For other controls this functionality works. I borrowed the template of this control from another project generated by you. And here starts another problem. When I want to create my control based on SfDataGrid compilation ends with an error:


I assume that I have all required packages:


What am I doing wrong? Best regards.

Below is my code:

<Style TargetType="{x:Type local:SfDataGridExt}">

        <Setter Property="Background" Value="Transparent" />

        <Setter Property="BorderBrush" Value="Gray" />

        <Setter Property="BorderThickness" Value="1" />

        <Setter Property="FontSize" Value="12" />

        <Setter Property="FontFamily" Value="Segoe UI" />

        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />

        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />

        <Setter Property="ScrollViewer.PanningMode" Value="Both" />

        <Setter Property="ScrollViewer.PanningRatio" Value="1" />

        <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />

        <Setter Property="Template">

            <Setter.Value>

                <ControlTemplate TargetType="{x:Type local:SfDataGridExt}">

                        <Grid SnapsToDevicePixels="True">

                            <VisualStateManager.VisualStateGroups>

                                <VisualStateGroup x:Name="CommonStates">

                                    <VisualState x:Name="Busy">

                                        <Storyboard>

                                            <BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_BusyDecorator" Storyboard.TargetProperty="IsBusyIndicatorShowing">

                                                <DiscreteBooleanKeyFrame KeyTime="0" Value="True" />

                                            </BooleanAnimationUsingKeyFrames>

                                        </Storyboard>

                                    </VisualState>

                                    <VisualState x:Name="Normal" />

                                </VisualStateGroup>

                            </VisualStateManager.VisualStateGroups>

                            <Grid.RowDefinitions>

                                <RowDefinition Height="Auto" />

                                <RowDefinition Height="*" />

                            </Grid.RowDefinitions>

                            <Border Grid.Row="0"

                                    SnapsToDevicePixels="True"

                                    Visibility="{Binding Path=ShowGroupDropArea,

                                                         RelativeSource={RelativeSource TemplatedParent},

                                                         Converter={StaticResource VisiblityConverter}}">

                                <syncfusion:GroupDropArea x:Name="PART_GroupDropArea" SnapsToDevicePixels="True" />

                            </Border>


                            <Border Grid.Row="1"

                                    Background="{TemplateBinding Background}"

                                    BorderBrush="{TemplateBinding BorderBrush}"

                                    BorderThickness="{TemplateBinding BorderThickness}"

                                    SnapsToDevicePixels="True">

                                <ScrollViewer x:Name="PART_ScrollViewer"

                                              CanContentScroll="True"

                                              FlowDirection="{TemplateBinding FlowDirection}"

                                              HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"

                                              IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"

                                              IsTabStop="False"

                                              PanningMode="{TemplateBinding ScrollViewer.PanningMode}"

                                              PanningRatio="{TemplateBinding ScrollViewer.PanningRatio}"

                                              VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">

                                    <syncfusion:VisualContainer x:Name="PART_VisualContainer" />

                                </ScrollViewer>

                            </Border>

                            <syncfusion:BusyDecorator x:Name="PART_BusyDecorator"

                                                      Grid.Row="1"

                                                      HorizontalAlignment="Center"

                                                      VerticalAlignment="Center" />


                        </Grid>

                </ControlTemplate>

            </Setter.Value>

</Style>

        </Setter>

    </Style>


6 Replies

DM Dhanasekar Mohanraj Syncfusion Team April 25, 2022 02:03 PM UTC

Hi Rob,

Based on the provided information, we have checked the reported issue in our end. The reference for VisiblityConverter is not available and we have to include the mentioned converter class which is present in Syncfusion name space like below,

Xaml :  

Namespace :

xmlns:syncfusion=http://schemas.syncfusion.com/wpf


Converter reference :

<syncfusion:BoolToVisiblityConverter x:Key="VisiblityConverter" />


We had prepared the sample based on provided information. Please check this and revert us if you need further assistance for thi
s.

Regards,
Dhanasekar M.


Attachment: Edit_Template_7f8e2518.zip


RO Rob April 25, 2022 05:08 PM UTC

Thank you for your quick reply. Unfortunately I had the above reference in my code, but I only pasted the Style related part and this reference was over. However, in your project it works, but not completely. When I want to use 2 times the same control it gives an error that the PropertyMetadata object is already registered for the type "SfDataGridExt". I don't understand why - it is possible that I am missing something because I am not an expert in creating controls :)





Best regards

Robert 



DM Dhanasekar Mohanraj Syncfusion Team April 26, 2022 01:58 PM UTC

Hi Rob,


We ca able to reproduce the reported issue in our end. We will validate and update you the details on April 28, 2022.


We appreciate your patience until then.


Regards,

Dhanasekar M.



DM Dhanasekar Mohanraj Syncfusion Team April 28, 2022 02:01 PM UTC

Hi Rob,

We analyzed the reported issue in our end. In that you are overriding the default style with its key inside the custom class constructor. It’s not needed to apply the style for custom datagrid. Without this the applied styles are reflected properly. We have modified the sample based on your scenario please check this and revert us if you need further assistance for this.

Regards,
Dhanasekar M.


Attachment: Edit_Template_(2)_f4fe6004.zip


RO Rob April 30, 2022 07:43 PM UTC

Hello  Dhanasekar ,

You're 100 percent right. I have always made my controls overriden the style of basic types like Control or ContentControl etc. Now it works great. Thank you and your team for your time and help in solving the problem. 

Best regards, 

Robert



DM Dhanasekar Mohanraj Syncfusion Team May 2, 2022 02:20 PM UTC

Hi Rob,

We are glad to know that the provided solution satisfies your requirement.

Regards,
Dhanasekar M.


Loader.
Up arrow icon