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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:35:42+00:00 2026-05-13T21:35:42+00:00

Hi i am trying to write a datatrigger in which i have to clear

  • 0

Hi i am trying to write a datatrigger in which i have to clear a textbox content on checkbox checked.My Code is given below

It works as long as you dont type anything in the textbox.As soon as i type in the textbox the datatrigger fails to work.How can i solve this

<Window x:Class="CheckboxTextbox.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">
    <Window.Resources>
        <Style x:Key="cbStyle" TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=Chk,Path=IsChecked}" Value="True">
                    <Setter Property="Text" Value="{x:Null}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <StackPanel>
        <CheckBox Name="Chk" Content="test"/>
        <TextBox Style="{StaticResource cbStyle}">

        </TextBox>
    </StackPanel>
</Window>
  • 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-13T21:35:43+00:00Added an answer on May 13, 2026 at 9:35 pm

    Unlike an animation which can “hold” a dependency property at a specified value once the animation ends, a DataTrigger sets the target property and then is done until the source property changes.

    In other words, in your example if you put some text in the text box, then check the box, the text will be cleared. But then if you start typing in the text box again, DataTrigger isn’t going to do anything until the check box changes again. That’s why when you uncheck and re-check the box, the text is cleared again.

    So what you may want to do is in your DataTrigger, set the text box’s IsReadOnly property to true. This will prevent you from typing in the box while the DataTrigger is active.

    <DataTrigger Binding="{Binding ElementName=Chk,Path=IsChecked}" Value="True">
        <Setter Property="Text" Value="{x:Null}"/>
        <Setter Property="IsReadOnly" Value="True"/>
    </DataTrigger>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying write a query to find records which don't have a matching record
In trying to write more testable Java code, I have been using the Model-View-Presenter
I m trying write code that after reset set up rrpmax as 3000. It
Trying to write a code at the moment that basically tests to see if
Trying to write a code that searches hash values for specific string's (input by
Im trying to write a recursive function which returns the factorial of a number.
Im trying to write a batch file which scans several files and looks for
I am trying to learn python, I was trying write C/C++ code i used
Trying to write a trivial application, But I have stuck into one of the
Trying to write a byte[] to a file, which i think is working correctly

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.