Binding to SmallIcon problem

Hi, I encounter a problem with binding the SmallIcon.

In my project I have a resource folder with png files: Assets\datagrid\Boolean-black.png

I use the following ButtonAdv code in XAML:

<syncfusion:ButtonAdv SmallIcon="{Binding Item0.Image, Mode=OneWay}"  SizeMode="Normal" />

The binding to Item0.Image gets the image to show depending on the Type of item0 as follows:

       public string Image

        {

            get

            {

                string str = this.Type.ToString();


                if (str == "System.String")

                    return @"pack://application:,,,/Assets/Datagrid/Text-black.png";

                else if (str == "System.Decimal")

                    return @"pack://application:,,,/Assets/Datagrid/Number-black.png";

                else if (str == "System.Boolean")

                    return @"pack://application:,,,/Assets/Datagrid/Boolean-black.png";

                else if (str == "System.DateTime")

                    return @"pack://application:,,,/Assets/Datagrid/Date-black.png";

                else if (str == "System.Int32" || str == "System.Int64")

                    return @"pack://application:,,,/Assets/Datagrid/Integer-black.png";

                else

                    return null;

            }

        }

This however does not work, i tried several options, nothign seem to work, except the following in XAML without a binding. 

<syncfusion:ButtonAdv SmallIcon="..\Assets\Datagrid\integer-black.png"  SizeMode="Normal" />

Could you please help me with this?





8 Replies

BA BagavathiPerumal Apranandham Syncfusion Team July 25, 2022 02:06 PM UTC

Hi jpz,


We are unable to reproduce the issue at our end; however, we've created a sample based on your requirement. please provide more details about the requirement, or modify our sample and revert to us with a reproducible issue or video. So, it will be helpful to prompt the solution further.

Please refer to the attached sample for your reference.

Note: In this sample, We have changed the button Image based on item type.


Regards,

Bagavathi Perumal A


Attachment: ButtonAdv_434e9855.zip


JP jpz replied to BagavathiPerumal Apranandham July 26, 2022 07:33 AM UTC

Thanks for your example, I added the following snippits (only the important code) along with some results. I hope this will make it more clear.

               <syncfusion:GridTemplateColumn HeaderText="Delete" AllowSorting="False" MappingName="">
                    <syncfusion:GridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <syncfusion:ButtonAdv
                                Name="smallButtonAdv"
                                Margin="2"
                                Height="25" Width="25"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Command="{Binding DataContext.ButtonDeleteCommand, ElementName=dataGrid}" CommandParameter="{Binding}"
                                Label=""
                                IconTemplate="{StaticResource IconDelete}"
                                SizeMode="Small"
                                Tag="Small"
                                syncfusion:FocusManagerHelper.FocusedElement="True"
                                />
                        </DataTemplate>
                    </syncfusion:GridTemplateColumn.CellTemplate>
                </syncfusion:GridTemplateColumn>
                <syncfusion:GridTemplateColumn HeaderText="Name" MappingName="FriendlyName" IsReadOnly="True">
                    <syncfusion:GridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid Margin="3">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="19" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Image
                                    Margin="3,0,0,0"
                                    Grid.Column="0"
                                    Width="16"
                                    Height="16"
                                    Source="{Binding Type, Converter={StaticResource typeImageConverter}}" />
                                <TextBlock
                                    Grid.Column="1"
                                    Padding="4"
                                    VerticalAlignment="Center"
                                    Text="{Binding FriendlyName, Mode=OneWay}"
                                    ToolTip="{Binding FriendlyName, Mode=OneWay}"
                                    />
                            </Grid>
                        </DataTemplate>
                    </syncfusion:GridTemplateColumn.CellTemplate>
                </syncfusion:GridTemplateColumn>


This gives the following:

Capture.PNG

This is the results I like to have, but is not done using the ButtonAdv, also note the aA is an icon and is the result of the typeImageConvertor listed below.

       public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                string str = value.ToString();

                if (str == "System.String")
                    return @"pack://application:,,,/Assets/Datagrid/Text-black.png";
                else if (str == "System.Decimal")
                    return @"pack://application:,,,/Assets/Datagrid/Number-black.png";
                else if (str == "System.Boolean")
                    return @"pack://application:,,,/Assets/Datagrid/Boolean-black.png";
                else if (str == "System.DateTime")
                    return @"pack://application:,,,/Assets/Datagrid/Date-black.png";
                else if (str == "System.Int32" || str == "System.Int64")
                    return @"pack://application:,,,/Assets/Datagrid/Integer-black.png";
                else
                    return null;
            }

            return null;
        }

The trashcan resource is defined like this:


<DataTemplate x:Key="IconDelete">
        <Grid>
            <Grid Name="backgroundGrid" Width="16" Height="16" Visibility="Collapsed" />
            <Path Stretch="Uniform" Fill="Black" Width="12" Height="12" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5" >
                <Path.Data>
                    <PathGeometry FillRule="Nonzero" Figures="M18,10L20,10 20,26 18,26 18,10z M14,10L16,10 16,26 14,26 14,10z M10,10L12,10 12,26 10,26 10,10z M6,6L6,29 6.296875,29.703125 7,30 23,30 23.703125,29.703125 24,29 24,6 6,6z M12,2L12,4 18,4 18,2 12,2z M12,0L18,0 18.78125,0.15625 19.4140625,0.5859375 19.84375,1.21875 20,2 20,4 28,4 28,6 26,6 26,29 25.765625,30.171875 25.125,31.125 24.171875,31.765625 23,32 7,32 5.828125,31.765625 4.875,31.125 4.234375,30.171875 4,29 4,6 2,6 2,4 10,4 10,2 10.15625,1.21875 10.5859375,0.5859375 11.21875,0.15625 12,0z" />
                </Path.Data>
                <Path.RenderTransform>
                    <TransformGroup>
                        <TransformGroup.Children>
                            <RotateTransform Angle="0" />
                            <ScaleTransform ScaleX="1" ScaleY="1" />
                        </TransformGroup.Children>
                    </TransformGroup>
                </Path.RenderTransform>
            </Path>
        </Grid>
    </DataTemplate>

The problem is that using an icon on the ButtonAdv does not work, I like to use a button in the second column, but for this demo I use the trashcan resource and substitute it for the aA icon like this:

                <syncfusion:GridTemplateColumn HeaderText="Delete" AllowSorting="False" MappingName="">

                    <syncfusion:GridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <syncfusion:ButtonAdv
                                Name="smallButtonAdv"
                                Margin="2"
                                Height="25" Width="25"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Command="{Binding DataContext.ButtonDeleteCommand, ElementName=dataGrid}" CommandParameter="{Binding}"
                                Label=""
                                SmallIcon="{Binding Type, Converter={StaticResource typeImageConverter}}"
                                SizeMode="Small"
                                Tag="Small"
                                syncfusion:FocusManagerHelper.FocusedElement="True"
                                />
                        </DataTemplate>
                    </syncfusion:GridTemplateColumn.CellTemplate>


This will give the following result: No icon displayed on the ButtonAdv item.

Capture2.PNG

I hope this explains my problem in more details.

Best regards, Jan Pieter



BA BagavathiPerumal Apranandham Syncfusion Team July 28, 2022 02:49 AM UTC

Hi jpz,



We have confirmed the reported scenario is a defect and logged a report for the reported scenario “SmallIcon Image is not rendered properly when using ButtonAdv on SfDateGrid”. We will include the fix in our upcoming Weekly NuGet release which is scheduled on 16th August 2022.


You can track the status of this defect using the following feedback link: SmallIcon Image is not rendered properly when using ButtonAdv on SfDateGrid in WPF | Feedback Portal (syncfusion.com)


If you have any more specification replication procedures or a scenario to be tested, you can add it as a comment in the portal.


Please let us know if you need any further assistance.





Regards,
Bagavathi Perumal A




JP jpz replied to BagavathiPerumal Apranandham July 28, 2022 02:38 PM UTC

Thanks!



BA BagavathiPerumal Apranandham Syncfusion Team August 17, 2022 11:29 AM UTC

Hi jpz,


Sorry for inconvenience,

We are still working this issue with high priority. We will update you the fix in our upcoming NuGet release which is scheduled on 23rd August 2022.

We appreciate your patience until then.



Regards,
Bagavathi Perumal A



BA BagavathiPerumal Apranandham Syncfusion Team August 23, 2022 01:02 PM UTC

Hi jpz,


We have included the fix for the reported issue “SmallIcon Image is not rendered properly when using ButtonAdv on SfDataGrid” in our Weekly NuGet release version 20.2.0.45 which is available for download ( https://www.nuget.org/).


We thank you for your support and appreciate your patience in waiting for this update. Please get in touch with us if you require any further assistance.



Regards,
Bagavathi Perumal A



JP jpz August 26, 2022 06:16 AM UTC

Thanks!



BA BagavathiPerumal Apranandham Syncfusion Team August 26, 2022 08:41 AM UTC

Hi jpz,


We hope that your issue is resolved. Please let us know if you need any other assistance. We are happy to assist you.


Regards,
Bagavathi Perumal A



Loader.
Up arrow icon