Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3315688
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:22:46+00:00 2026-05-17T22:22:46+00:00

I have the following ListView: <ListView Name=listView> <ListView.View> <GridView> <GridView.ColumnHeaderContainerStyle> <Style TargetType={x:Type GridViewColumnHeader}> <Setter

  • 0

I have the following ListView:

    <ListView Name="listView">
            <ListView.View>
                <GridView>
                    <GridView.ColumnHeaderContainerStyle>
                        <Style TargetType="{x:Type GridViewColumnHeader}">
                            <Setter Property="Visibility"
                                    Value="Collapsed"/>
                        </Style>
                    </GridView.ColumnHeaderContainerStyle>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <CheckBox
                                          Margin="0"
                                          VerticalAlignment="Center"
                                          IsChecked="{Binding IsChecked}"
                                          Visibility="{Binding IsChecked, Converter={StaticResource boolToVis}}">
                                    </CheckBox>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Margin="0"
                                           Text="{Binding Text}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>

The items in the ListView are of the below type:

public class CheckBoxListViewItemSource : INotifyPropertyChanged
{
    public CheckBoxListViewItemSource(String text)
    {
        m_text = text;
    }

    public bool IsChecked
    {
        get { return m_checked; }
        set
        {
            if (m_checked == value) return;
            m_checked = value;
            RaisePropertyChanged("IsChecked");
        }
    }

    public String Text
    {
        get { return m_text; }
        set
        {
            if (m_text == value) return;
            m_text = value;
            RaisePropertyChanged("Text");
        }
    }

    public override string ToString()
    {
        return Text;
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void RaisePropertyChanged(string propName)
    {
        PropertyChangedEventHandler eh = PropertyChanged;
        if (eh != null)
        {
            eh(this, new PropertyChangedEventArgs(propName));
        }
    }

    private bool m_checked;
    private String m_text;
}

The visibility of the checkbox in the ListView is bound to the value of IsChecked of the ListViewItem. The converter is a simple bool to visibility converter:

public class BoolToVisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter,
                          CultureInfo culture)
    {
        if (value is Boolean)
        {
            return ((bool)value) ? Visibility.Visible : Visibility.Collapsed;
        }

        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter,
                              CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

In the code behind of the ListView I have:

    void listView_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        foreach (var item in e.RemovedItems)
        {
            CheckBoxListViewItemSource source = item as CheckBoxListViewItemSource;
            source.IsChecked = false;
        }
        foreach (var item in e.AddedItems)
        {
            CheckBoxListViewItemSource source = item as CheckBoxListViewItemSource;
            source.IsChecked = true;
        }
    }

The binding for the checkbox visibility is not working for me. The default IsChecked value is false so the list appears with no checkboxes. If I select an item, the checkbox does not appear.

However, if I set the default value of IsChecked to true, all of the list items appear with a checkbox and if I select an item and then deselect it, the checkbox correctly disappears.

What I am trying to achieve is that all of the items start off with no checkbox, selecting an item displays a checked checkbox, and deselecting an item hides the checkbox.

Any ideas where I am going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:22:47+00:00Added an answer on May 17, 2026 at 10:22 pm

    Manually set width of the first GridViewColumn to a fixed value. It seems ListView sets width of it to zero if it contains nothing and doesn’t update width when checkboxes start to appear.

    Alternatively, change code of BoolToVisibilityConverter to return Visibility.Hidden instead of Visibility.Collapsed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following GridView : <ListView Name=TrackListView ItemContainerStyle={StaticResource itemstyle}> <ListView.View> <GridView> <GridViewColumn Header=Title
I have the following code in xaml: <ListView Name=listView1 IsSynchronizedWithCurrentItem=True > <ListView.View> <GridView> <GridViewColumn
I have the following ListView : <ListView Name=TrackListView> <ListView.View> <GridView> <GridViewColumn Header=Title Width=100 HeaderTemplate={StaticResource
I have the follwoing listview in my xaml: <ListView Name=listView1> <ListView.View> <GridView> <GridViewColumn Width=Auto
I have ListView that has the following EditItemTemplate: <EditItemTemplate> <tr style=> <td> <asp:LinkButton ID=UpdateButton
I have the following view <ul data-role=listview data-inset=true> <!-- ko with: model.Item_selected --> <li
I have the following ListView with a custom list item: I would like to
I have the following ListView in which I am using the JQuery UI sortable
I have the following listview : http://www.vogella.de/articles/AndroidListView/article.html the chaper: 8. Tutorial: Domain Model and
I have been following the following post on using multiple ItemTemplates in a ListView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.