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

  • Home
  • SEARCH
  • 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 8359911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:18:06+00:00 2026-06-09T11:18:06+00:00

The general problem I want to solve is to have just one datatemplate for

  • 0

The general problem I want to solve is to have just one datatemplate for a checkbox which I can then use for many different columns in a listview (using a gridview). In all examples I’ve seen a seperate template is created for each binding which seems overkill to me.

I’ve been trying to do this by creating an attached property that the gridviewcolumn will set. Then I can simply have one datatemplate for a checkbox that binds to that attached property.

The problem I’m having is actually setting the checkbox source to the gridviewcolumn.

Here is the xaml:

<DataTemplate x:Key="CheckBoxTemplate">
    <CheckBox IsChecked="{Binding Path=(ap:AttachedProperties.IsChecked),
        RelativeSource={RelativeSource AncestorType={x:Type GridViewColumn}}}" />
</DataTemplate>

<GridView x:Key="MyGridView">
    <GridViewColumn Header="CheckBox" CellTemplate="{StaticResource CheckBoxTemplate}" ap:AttachedProperties.IsChecked="{Binding Path=SomeValue}" />
</GridView>

P.S. The Attached property is working fine, I’ve attached it directly to the checkbox and used a relativesource self binding and gotten the values coming through, but when I try to bind it on the GridViewColumn I get no happiness, in fact I haven’t been able to bind to the Header on the GridViewColumn either…

P.P.S I have tried other binding source expressions as well (just not the right one it seems)…

Edit:
Immediately after posting this it dawned on me that the GridViewColumn exists for all rows and so that is probably why this isn’t working?!

I’ve slept on it now and realise that doing things in this way wont work (because the GridViewColumn can only hold the value for the first row not each row as I would need it to) – however I still would have thought it possible to bind to the GridViewColumn?

Here is a xaml only example to show the behaviour:

<Window x:Class="WpfApplication3.MainWindow"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       Title="MainWindow"
       Width="525"
       Height="350">
   <Grid>
       <ListView Name="listView1"
                 Width="479"
                 Height="287"
                 Margin="12,12,0,0"
                 HorizontalAlignment="Left"
                 VerticalAlignment="Top">
           <ListView.View>
               <GridView>
                   <GridViewColumn Header="A Header">
                       <GridViewColumn.CellTemplate>
                           <DataTemplate>
                               <StackPanel>
                                   <TextBlock Text="{Binding Path=Header, RelativeSource={RelativeSource AncestorType={x:Type GridViewColumn}}}" />
                                   <TextBlock Text="Visible row" />
                               </StackPanel>
                           </DataTemplate>
                       </GridViewColumn.CellTemplate>
                   </GridViewColumn>
               </GridView>
           </ListView.View>
           <ListViewItem />
           <ListViewItem />
       </ListView>
   </Grid>
</Window>

Under such a scenerio I would expect to see “A Header” just above each “Visible row” text

  • 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-06-09T11:18:08+00:00Added an answer on June 9, 2026 at 11:18 am

    I’ve check snoop, the reason why that is not working because GridColumnHeader is not in the VisualTree where the GridRows are. My solution is to use ElementName and bind it to the Header property. Fairly simple, much cleaner and readable.

        <ListView Name="listView1"
                 Width="479"
                 Height="287"
                 Margin="12,12,0,0"
                 HorizontalAlignment="Left"
                 VerticalAlignment="Top">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="A Header" x:Name="HeaderOne">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel>
                                    <TextBlock Text="{Binding ElementName=HeaderOne,Path=Header}" />
                                    <TextBlock Text="Visible row" />
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
            <ListViewItem />
            <ListViewItem />
        </ListView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this problem that I can't just solve algorithmically. Let's say i have
I have an interesting problem to solve. One of my clients has me developing
what's up? :-) I have one problem and i hope you can help me
Don't be scared of the extensive code. The problem is general. I just provided
just had a general question about how to approach a certain problem I'm facing.
I have a problem to solve involving reading large files, and I have a
Here is the general description of my problem. I have folder for my favourite
I have custom view in my application which can be scrolled by the user.
I think I have a pretty easy problem to solve, but I have been
I know about the svn:ignore property, but that doesn't solve my problem. I have

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.