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 8854439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:52:51+00:00 2026-06-14T13:52:51+00:00

I have a DataGrid that I am creating and populating from code. When the

  • 0

I have a DataGrid that I am creating and populating from code. When the grid first shows up the RadioButton column, “Include”, seems to work just fine. The problem is that after I change the sort the RadioButton no longer works correctly. You can spam click on it, click out of the window and then come back in, or maybe event just wait, it will eventually work, but obviously it isn’t really usable. Here is an simple example:

using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            InitializeDataGrid();
        }

        private void InitializeDataGrid()
        {
            var table = GetTestTable();

            var newGrid = new DataGrid
                              {
                                  CanUserAddRows = false,
                                  CanUserSortColumns = true,
                                  AutoGenerateColumns = true,
                                  ItemsSource = table.AsDataView(),
                                  DataContext = table
                              };
            newGrid.AutoGeneratingColumn += dataGrid_AutoGeneratingColumn;

            UxRootGrid.Children.Add(newGrid);
        }

        private static DataTable GetTestTable()
        {
            DataTable table = new DataTable("name");
            table.Columns.Add("Include", typeof (bool));
            table.Columns.Add("Number", typeof (int));

            for (int i = 0; i < 5; i++)
            {
                var row = table.NewRow();
                row[0] = false;
                row[1] = i;
                table.Rows.Add(row);
            }
            return table;
        }

        void dataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
        {
            if (e.PropertyName != "Include")
            {
                return;
            }

            DataTemplate template = GetDataTemplate();
            DataGridTemplateColumn templateColumn = new DataGridTemplateColumn
                                                        {
                                                            Header = "Include",
                                                            CellTemplate = template,
                                                            CellEditingTemplate = template,
                                                        };
            e.Column = templateColumn;
        }

        private static DataTemplate GetDataTemplate()
        {
            var elementFactory = new FrameworkElementFactory(typeof (RadioButton));

            var binding = new Binding("Include")
                              {
                                  Mode = BindingMode.TwoWay,
                                  UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                              };

            elementFactory.SetBinding(ToggleButton.IsCheckedProperty, binding);
            elementFactory.SetValue(RadioButton.GroupNameProperty, "BindingGroup");

            return new DataTemplate {VisualTree = elementFactory};
        }
    }
}

Here is the Xaml:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel Name="UxRootGrid">
    </StackPanel>
</Window>

So, to see the problem:
1. Start the application
2. Click on the RadioButton next to the Number 1.
3. Click on the “Number” header twice (to sort in descending order).
4. Now click on the RadioButton next to the Number 4.
5. Notice that the RadioButton next to the Number 1 is now deselected, but that the RadioButton next to the Number 4 is not selected.
6. Click on the RadioButton next to the Number 4 a few more times. Eventually it will become selected.

UPDATE: I had another of my coworkers try this on his machine, and it took him a time or 2 more of sorting / selecting radio buttons to see the issue happen, but eventually he ended up in the same position as me.

I’m pretty new to WPF, so I’m hoping this is just a simple mistake on my part. Any help in getting a workaround or another method of setting this up would be greatly appreciated.

  • 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-14T13:52:52+00:00Added an answer on June 14, 2026 at 1:52 pm

    I was able to solve the problem by using the RadioButtonExtended class by Peter Staev, located here: http://pstaev.blogspot.com/2008/10/binding-ischecked-property-of.html

    As he suggests in his post, I just replaced the usages of RadioButton with RadioButtonExtended and then did my binding to IsCheckedReal rather than IsChecked.

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

Sidebar

Related Questions

I have a dynamic Datagrid that I have created. I am creating each column
I'm working on creating a datagrid that has a checkbox column. I have some
I have a datagrid that is filled with a dataset from an SQL query.
I have a datagrid that I have filled with data from a sql database.
I am creating the DataGrid and RowDetailsTemplate in code, so I don't have XAML
i have a datagrid that load the data from my database. in my datagrid,
I have a DataGrid that represents layers - each row is an image on
I have a datagrid that I want to add a button/s to at runtime.
I have a DataGrid that needs to show a gradient background on mouseover of
I have a DataGrid that is showing some data via a PagedCollectionView with one

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.