We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to filter a GridImageColumn

Hi,

in a sfDataGrid I have a GridImageColumn that is binded to a property of type BitmapImage (they are returned some particular bitmaps that are in a resource file).

I'd like to set the property AllowFiltering to true.

But when I try to click to this column's filter I obtain all the same strings related to the default ToString method of BitmapImage ("System.Windows.Media.Imaging.BitmapImage).

I'd like, instead, to be able to supply a correct description string related to each image but I don't know how is it possibile to set them.

Can anyone help me ?


Silvio


3 Replies

SJ Sathiyathanam Jeyakumar Syncfusion Team March 22, 2023 07:40 AM UTC

Hi Silvio,

Approach 1: If you need to display an image in a CheckBoxFilterControl, you can use the following approach. This approach we need to edit the CheckBoxFilterControl template. Refer to the below code snippets to get more information.

<Syncfusion:GridImageColumn AllowEditing="False" HeaderText="Country" MappingName="ImageLink">

    <Syncfusion:GridImageColumn.FilterPopupStyle>

        <Style TargetType="Syncfusion:GridFilterControl">

            <Setter Property="CheckboxFilterStyle">

                <Setter.Value>

                    <Style TargetType="Syncfusion:CheckboxFilterControl">

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

                        <Setter Property="ItemTemplate">

                            <Setter.Value>

                                <DataTemplate>

                                    <CheckBox Margin="4"

                                                HorizontalAlignment="Stretch"

                                                HorizontalContentAlignment="Stretch"

                                                Focusable="False"

                                                Content="{Binding}"   

                                                FontWeight="{Binding FontWeight,RelativeSource={RelativeSource Self}}"

                                                Foreground="{Binding Foreground,RelativeSource={RelativeSource Self}}"

                                                IsChecked="{Binding IsSelected,

                                                                    Mode=TwoWay}">

                                        <CheckBox.ContentTemplate>

                                            <DataTemplate>

                                                <Image Source="{Binding Path=ActualValue}"

                                                        HorizontalAlignment="Left"

                                                        Height="25"/>

                                            </DataTemplate>

                                        </CheckBox.ContentTemplate>

                                    </CheckBox>

                                </DataTemplate>

                            </Setter.Value>

                        </Setter>

                    </Style>

                </Setter.Value>

            </Setter>

        </Style>

    </Syncfusion:GridImageColumn.FilterPopupStyle>

</Syncfusion:GridImageColumn>


Output:



Approach 2: If you need to display an image in the UI and then display a string representation of the same image in a CheckBoxFilterControl, you can use the following approach.This approach can be achieved by using the TextColumn with a cell template. Please refer to the code snippets below for more information.

<Syncfusion:GridTextColumn AllowEditing="False"

                    HeaderText="Country"

                    TextAlignment="Center"

                    MappingName="Country">

    <Syncfusion:GridTextColumn.CellTemplate>

        <DataTemplate>

            <Image Source="{Binding Path=Country, Converter={StaticResource stringToImageConverter}}" Stretch="Uniform"/>

        </DataTemplate>

    </Syncfusion:GridTextColumn.CellTemplate>

</Syncfusion:GridTextColumn>

Converter

public class StringToImageConverter : IValueConverter

{    

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

    {

        string imagename = value as string + ".png"; ;

        return new BitmapImage(new Uri(string.Format(@"..\..\Images\{0}", imagename), UriKind.Relative));

    }

       

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

    {

        return null;

    }

}


Output:


Regards,

Sathiyathanam


Attachment: CheckBoxFilterControlImage_6f5431c.zip


SI Silvio March 29, 2023 09:58 AM UTC

Thank you for this sugestions.


I tried approach 1 and it works very well, but I have a problem.

I allowed the user to set VisualStyle to FluentDark or FluentLight in the application, but the FilterPopup does not follow the style and remains white.

How do I make it follow the chosen style?



DM Dhanasekar Mohanraj Syncfusion Team March 30, 2023 02:33 PM UTC

Silvio,

We have checked the reported issue with the provided details. In that, when you are using an external theme along with styling these kinds of problems occur. However, you can overcome this by using based on the property for the applied styling like below,

XAML:

<Application.Resources>

    <ResourceDictionary>

        <ResourceDictionary.MergedDictionaries>

            <ResourceDictionary Source="/Syncfusion.Themes.FluentDark.WPF;component/SfDataGrid/SfDataGrid.xaml"/>

            <ResourceDictionary Source="/Syncfusion.Themes.FluentDark.WPF;component/MSControl/ScrollViewer.xaml"/>

            <ResourceDictionary Source="/Syncfusion.Themes.FluentDark.WPF;component/MSControl/Button.xaml"/>

            <ResourceDictionary Source="/Syncfusion.Themes.FluentDark.WPF;component/MSControl/CheckBox.xaml"/>

            <ResourceDictionary Source="/Syncfusion.Themes.FluentDark.WPF;component/MSControl/TextBox.xaml"/>

            <ResourceDictionary Source="/Syncfusion.Themes.FluentDark.WPF;component/MSControl/TextBlock.xaml"/>

        </ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>

</Application.Resources>

<Syncfusion:GridImageColumn.FilterPopupStyle>

    <Style TargetType="Syncfusion:GridFilterControl" BasedOn="{StaticResource SyncfusionGridFilterControlStyle}" >

        <Setter Property="CheckboxFilterStyle">

            <Setter.Value>

                <Style TargetType="Syncfusion:CheckboxFilterControl">

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

                    <Setter Property="ItemTemplate">