Change the RadTileViewItem Header Background
This article will show you how to change the Background of the RadTileViewItems' Header corresponding to the state of the item in an MVVM scenario.
The final result should look like this:
The Header of the RadTileViewItem is designed as a separate ContentControl and you can apply a custom style to it. In order to do this you have to add the following namespace into your application:
Next, you can define a custom style targeting the TileViewItemHeader control and bind its Background property to a property defined in your business model like this:
The Foreground is changed just to make the text in the header easy to read.
Also, in order to visualize your items you can create one more Style targeting the RadTileViewItem. In that style you can bind the Header property to a property defined in your business model. By doing so you will be able to set the text of the header. You can use the following code:
In order to track the state of each RadTileViewItem you can define a property in your business model and bind it to the TileState property of the item. This can be done by adding one more Setter to the last Style and it will look like this:
To finalize the XAML code you can define the following RadTileView control:
Next step is to set up your business model. First you can create an ItemViewModel class which derives from Telerik's ViewModelBase. This class can expose properties that will hold the text of the Header, the color of the Background and the CurrentState of the item. Furthermore, the item has to know which color to apply to its header in each state. This is why the constructor of the item can receive three colors - one for each state. Also, this class can expose a private method which changes the color of the header and it will be called whenever the state of the corresponding item is changed. Below is the implementation of that class.
After your ItemViewModel is ready, you can define a collection of items. Create a MainViewModel class which exposes one property of type ObservableCollection
Finally, you can set the MainViewModel as DataContext of your application. This can be done just after the InitializeComponent() method like this: