diff --git a/wpf/Button/Getting-Started.md b/wpf/Button/Getting-Started.md index 65b71f0ef..001c551eb 100644 --- a/wpf/Button/Getting-Started.md +++ b/wpf/Button/Getting-Started.md @@ -305,7 +305,7 @@ The [IconTemplate](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Tools.C {% highlight XAML %} - + + + + + - + - + - + + - - + + @@ -355,28 +361,49 @@ The [IconTemplate](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Tools.C {% highlight c# %} - public class TemplateSelector : DataTemplateSelector - { - public DataTemplate NewIcon { get; set; } - public DataTemplate OpenIcon { get; set; } - public override DataTemplate SelectTemplate(object item, DependencyObject container) + public class ViewModel : INotifyPropertyChanged { - if (item == null) - { - return OpenIcon; - } - if ((item as Model).IsChecked) - { - return NewIcon; - } - return base.SelectTemplate(item, container); + private bool _isChecked; + public bool IsChecked + { + get { return _isChecked; } + set + { + if (_isChecked != value) + { + _isChecked = value; + OnPropertyChanged(nameof(IsChecked)); + } + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + protected void OnPropertyChanged(string propertyName) => + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public class IconTemplateSelector : DataTemplateSelector + { + public DataTemplate CheckedIcon { get; set; } + public DataTemplate UnCheckedIcon { get; set; } + + public override DataTemplate SelectTemplate(object item, DependencyObject container) + { + if (item is bool isChecked) + { + return isChecked ? CheckedIcon : UnCheckedIcon; + } + return base.SelectTemplate(item, container); + } } - } {% endhighlight %} {% endtabs %} +![IconTemplateSelector in WPF Button](Getting-Started_images/Getting-Started_IconTemplateSelector.gif) + N> The [ButtonAdv](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Tools.Controls.ButtonAdv.html) loads the icon in the following priority order. * [IconTemplateSelector](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Tools.Controls.ButtonAdv.html#Syncfusion_Windows_Tools_Controls_ButtonAdv_IconTemplateSelector) * [IconTemplate](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Tools.Controls.ButtonAdv.html#Syncfusion_Windows_Tools_Controls_ButtonAdv_IconTemplate) diff --git a/wpf/Button/Getting-Started_images/Getting-Started_IconTemplateSelector.gif b/wpf/Button/Getting-Started_images/Getting-Started_IconTemplateSelector.gif new file mode 100644 index 000000000..33e74f87d Binary files /dev/null and b/wpf/Button/Getting-Started_images/Getting-Started_IconTemplateSelector.gif differ