(X) Hide this
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .

Using converters with binding to change foreground brush to accent brush

(0 votes)
0 comments   /   posted by Silverlight Show on Sep 19, 2013
Tags:   windows-phone , toni-petrina
Read original post by Toni Petrina at Toni codes .NET

Windows Phone has a concept of accent brush – a special color that can be changed in system settings which applications can use to single-out items of interest.

It is easy to apply accent brush to those controls for which we know in advance they will need to be singled-out, but things get tricky with dynamic data. For example, if only some items in a list need to be accented, like favorites, you need to change foreground just for those items. If you are using MVVM, you will probably have some bindable property named IsFavorite or IsImportant.

But how do you get a brush from some boolean property? Using converters. The converter will take the bool value and decide which brush to return depending on the value. Since you want to apply accent color only to those items that satisfy some condition, if the input value is true, you will get accent brush. Otherwise, you will get the default foreground brush.


Comments

No comments

Add Comment

Login to comment:
  *      *       

Our News on Twitter