Public class BooleanToBrushConverter : DependencyObject, IValueConverter The first code block show the implementation of the converter class. Everything fully declarative in my XAML file without a single line of C# code. BooleanToBrushConverter exposes two dependency properties TrueBrush and FalseBrush and by providing values for these properties, the Boolean values true and false are mapped to Brush objects in the user interface accordingly. ![]() This converter class is intended to be used whenever a Boolean property is data bound to some UI element’s brush. In fact, I encountered this use case that often, that I decided to cover it in a custom converter class called BooleanToBrushConverter, which implements this functionality. The most common case for that is possibly an active / inactive state of a ViewModel which should reflect in the user interface. The first thing, we will define the enumeration that will be used in the conversion.NET C# Windows Phone Windows Phone 7 WP7 Silverlight WPF MVVMĪ common use case in Windows Phone (or generally Silverlight / WPF) development is having to change a UI element’s color (background and/or foreground) depending on a Boolean state in your ViewModel. In case of the inverse operation of conversion is needed, then you need to define the convertBack method.
0 Comments
Leave a Reply. |