Setting icon template selector Example missing "TemplateSelector" c# class

I am following the Getting Started of ButtonbAdv.

The following line in the "Setting icon template selector" section 

<local:TemplateSelector x:Key="IconTemp" NewIcon="{StaticResource newIcon}" OpenIcon="{StaticResource OpenIcon}"/>

suggests that there is a 

local:TemplateSelector 

class in the project.

However the contents of this c# class is not showed but necessary for the working of the sample.

Can you please provide the code of this class?

Axel



1 Reply

SM Subashini Mahendran Syncfusion Team February 2, 2022 10:45 AM UTC

Hi Axel,


Thank you for contacting Syncfusion support.


We have prepared a sample based on your requirement in which we have shown different images in ButtonAdv control based on its data context by using IconTemplateSelector property. Please find the code snippet, and sample for the same from below location.


Code Snippet:

XAML:

   

<local:TemplateSelector x:Key="IconTemp"

                                        NewIcon="{StaticResource newIcon}"

                                        OpenIcon="{StaticResource OpenIcon}"/>

 

<syncfusion:ButtonAdv x:Name="buttonAdv"

                                       HorizontalAlignment="Center"

                                       Margin="10"

                                       Label="New"

                                       IconTemplateSelector="{StaticResource IconTemp}"/>

 

C#:

public class TemplateSelector : DataTemplateSelector

{

        public DataTemplate NewIcon { get; set; }

        public DataTemplate OpenIcon { get; set; }

 

        public override DataTemplate SelectTemplate(object item, DependencyObject container)

        {

            if (item != null && item is Model && (item as Model).IsChecked)

            {

                return NewIcon;

            }

            else

            {

                return OpenIcon;

            }

        }

}


Sample: ButtonAdv-IconTemplateSelector-sample


Please try this above solution and let us know if it is helpful. 


Regards,

Subashini M.


Loader.
Up arrow icon