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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:47:18+00:00 2026-05-11T19:47:18+00:00

I’ve been trying to create my generic ReadOnlyCheckBox style/template but I’m having a problem

  • 0

I’ve been trying to create my generic ReadOnlyCheckBox style/template but I’m having a problem with the binding to the data. In the example here:

A read-only CheckBox in C# WPF

you bind directly to the data from the ControlTemplate definition, but of course this is not really what I want, as I want to be able to declare the new checkbox something like this:

        <CheckBox x:Name="uiComboBox" Content="Does not set the backing property, but responds to it."
Style="{StaticResource ReadOnlyCheckBoxStyle}" IsChecked="{Binding MyBoolean}"  Click="uiComboBox_Click"/>

Except of course when I do this and then set the event trigger on the bullet to be a TemplateBinding of IsChecked I have exactly what I started with! I guess I don’t understand why setting the binding directly in the bullet is different from setting IsChecked and then binding to that, isn’t the TemplateBinding just a way of referencing what is set in the properties of the control being created? How is the Click triggering the UI update even tho the data does not get updated? Is there a trigger for Click I can override to stop the update?

I got all the DictionaryResource stuff working fine so I am happy with that, cheers for the pointer.

The other thing I was curious about was if it is possible to reduce my Control/Style template by using the BasedOn parameter in the style, then I would only override the things I actually need to change rather than declaring a lot of stuff that I think is part of the standard template anyway. I might have a play with this.

Cheers

ed

  • 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-11T19:47:18+00:00Added an answer on May 11, 2026 at 7:47 pm

    The problem you’re running into is that you’re trying to use DataBinding where you shouldn’t.

    I disagree with other answers you’ve been getting in the link you’ve posted. While the ControlTemplate solutions appear neat and tidy, they don’t get at the heart of your problem, which is, you’re trying to use a single control (a CheckBox) to do two different things: show state (e.g. checked/unchecked) and perform logic (remote device, etc.).

    ControlTemplates are designed to change the way a control appears, but not behaves. You’re trying to change behavior, not appearance. See “What Is a ControlTemplate?” here for more details

    To do that, you’re going to have to store some forego the standard binding and handle some events:

    XAML:

    <Window x:Class="WPFCheckBoxClickTester.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
        <Grid>
            <CheckBox x:Name="foo" Checked="foo_Checked"></CheckBox>
        </Grid>
    </Window>
    

    Code-Behind:

    using System.ComponentModel;
    using System.Threading;
    using System.Windows;
    
    namespace WPFCheckBoxClickTester
    {
        /// <summary>
        /// Interaction logic for Window1.xaml
        /// </summary>
        public partial class Window1 : Window
        {
            private BackgroundWorker _worker = new BackgroundWorker();
    
            public Window1()
            {
                InitializeComponent();
    
                foo.IsThreeState = false;
                this._worker.DoWork += new DoWorkEventHandler(_worker_DoWork);
                this._worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_worker_RunWorkerCompleted);
            }
    
            private void _worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
            {
                foo.IsChecked = true;
                foo.IsEnabled = true;
                return;
            }
    
            private void _worker_DoWork(object sender, DoWorkEventArgs e)
            {
                Thread.Sleep(500);
                return;
            }
    
            private void foo_Checked(object sender, RoutedEventArgs e)
            {
                if( foo.IsChecked == true && this.foo.IsEnabled )
                {
                    this.foo.IsChecked = false;
                    this.foo.IsEnabled = false;
    
                    this._worker.RunWorkerAsync();
                }
                return;
            }
    
        }
    }
    

    The above code example gives you the ability to execute some code async via BackgroundWorker — I’ve put in a Thread.Sleep as a placeholder. I’m also using foo.IsEnabled as a sentinel value in foo_Checked, but you may need some extra state here to handle all of your cases (for instance, going from Checked to Unchecked).

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

Sidebar

Ask A Question

Stats

  • Questions 154k
  • Answers 154k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'll have to change the RepeatLayout property and setting it… May 12, 2026 at 10:25 am
  • Editorial Team
    Editorial Team added an answer Your first question's pretty straightforward. Any file that you need… May 12, 2026 at 10:25 am
  • Editorial Team
    Editorial Team added an answer Adding the appropriate chdir (back to Phorums include path root)… May 12, 2026 at 10:25 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.