Boolean column with a converter

3 posts, 0 answers
  1. Patrick
    Patrick avatar
    504 posts
    Member since:
    Aug 2012

    Posted 05 May 2014 Link to this post

    I have a GridView that contains a column bound to a Boolean value.
    I want that the value is not displayed with the default check box, so I wrote a converter that displays a check mark only when the value is true.

    If I use the converter only on the DataContext, the column is still displayed with the standard check box:
    DataContext="{Binding IsTeamMate, Converter={StaticResource BooleanToCheckMark}}"

    To have the column displayed normally, I had to define a cell template:
    <tk:GridViewDataColumn DataContext="{Binding IsTeamMate, Converter={StaticResource BooleanToCheckMark}}"
                           Header="Already played"
          <TextBlock Text="{Binding IsTeamMate, Converter={StaticResource BooleanToCheckMark}}" />

    Is it a normal behavior or is there another way to display the column correctly ?
  2. Dimitrina
    Dimitrina avatar
    3769 posts

    Posted 06 May 2014 Link to this post


    By default when the bound value is of type Boolean, a CheckBox will be created as cell element.
    How have you defined the Converter you are referring to?

    I tested with the following code in the Convert method:
    public partial class BooleanToCheckMark : IValueConverter
         public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
             if (!value)
                 return "False";
             return true ;

    As a result I got some of the cells with a CheckBox marked as true and some cells with text "False".

    Basically you need to return the original Boolean value if it is true and a string otherwise.

    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
  3. Patrick
    Patrick avatar
    504 posts
    Member since:
    Aug 2012

    Posted 06 May 2014 in reply to Dimitrina Link to this post

    Hi Didie,
    thank you for the answer.
    My converter returns either an empty string (for false) or a string containing "✔" (for true).
    So this should work.
Back to Top