I have a toolbar that binds it’s ItemsSource to my VM, it’s a list of ToolBarItem
public class ToolbarItem : ObservableObject
{
public string ToolTip { get; set; }
public ICommand Command { get; set; }
public BitmapImage Icon { get; set; }
private bool _isPressed;
public bool IsPressed
{
get { return _isPressed; }
set { _isPressed = value; RaisePropertyChanged("IsPressed"); }
}
public ToolbarItem(string tooltip, ICommand command, BitmapImage icon)
{
this.Icon = icon;
this.Command = command;
this.ToolTip = tooltip;
}
}
}
this is my Toolbar item template:
<DataTemplate x:Key="toolBarItemTemplate">
<Button x:Name="toolBarButton"
ToolTip="{Binding Path=ToolTip}"
Command="{Binding Path=Command}"
Cursor="Hand"
Style="{StaticResource toolBarButtonItemStyle}">
<ContentControl Content="{Binding}" ContentTemplate="{StaticResource toolBarButtonItemTemplate}" />
</Button>
</DataTemplate>
<DataTemplate x:Key="toolBarButtonItemTemplate">
<Image Width="16"
Height="16"
Source="{Binding Path=Icon}"
Style="{StaticResource toolBarButtonImageStyle}" />
</DataTemplate>
What I want to do is, when the user clicks on specific toolbar button to change that button behavior, for example, have a border around it.
the way to do it, is using ItemTemplateSelector and based on the item’s type, use a different DataTemplate.
this is done in code