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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:19:21+00:00 2026-05-29T17:19:21+00:00

I have a UserControl that exists of only two TextBlocks: <UserControl […] x:Name=root> <StackPanel

  • 0

I have a UserControl that exists of only two TextBlocks:

<UserControl [...] x:Name="root">
    <StackPanel Orientation="Vertical">
        <TextBlock Text="{Binding Text1, ElementName=root}" /> 
        <TextBlock Text="{Binding Text2, ElementName=root}" />
    </StackPanel> 
</UserControl>

The corresponding code-behind looks like this:

public static readonly DependencyProperty Text1Property = DependencyProperty.Register("Text1", typeof(String), typeof(CmpText)); 
public static readonly DependencyProperty Text2Property = DependencyProperty.Register("Text2", typeof(String), typeof(CmpText)); 

public string Text1 
{ 
    get { return (string)GetValue(Text1Property); } 
    set { SetValue(Text1Property, value); } 
} 

public string Text2 
{ 
    get { return (string)GetValue(Text2Property); } 
    set { SetValue(Text2Property, value); } 
}

And this is how I use this UserControl in MainWindow.xml:

<local:CmpText Text1="{Binding Password1}" Text2="{Binding Password2}" />

What I basically want is the second TextBlock’s background to change its color to red if both Text1 and Text2 are unequal.

I tried to use a helper property in the code-behind:

public bool IsEqual { get { return Text1 == Text2; } }

And set the second TextBlock’s Style to

<Style TargetType="{x:Type TextBlock}"> 
     <Style.Triggers> 
         <DataTrigger Binding="{Binding IsEqual, ElementName=root}" Value="True"> 
             <Setter Property="Background" Value="Red"/> 
         </DataTrigger> 
     </Style.Triggers> 
 </Style>

However, IsEqual always turns out to be ‘true’ (and the TextBlock’s background is always red) even if the Text1 & Text2 properties don’t match. I think my helper property ‘IsEqual’ compares the default values of Text1 & Text2, which happen to be NULL (I don’t have any way to confirm that, since I cannot debug the GUI). So the evaluation of IsEqual seems to happen before my text properties get assigned any values. I want the evaluation to happen after the text properties get assigned.

I don’t know how to proceed. Can you help?

  • 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-29T17:19:23+00:00Added an answer on May 29, 2026 at 5:19 pm

    Currently there is no way that WPF could find out that IsEqual has changed, so the binding won’t be re-evaluated.

    You could do three things:

    1. Make IsEqual another dependency property and add PropertyChangedCallbacks to the Text1 and Text2 which, whenever they change, update IsEqual.

    2. Or, implement INotifyPropertyChanged and raise the PropertyChanged event for IsEqual in the Text1 and Text2 PropertyChangedCallbacks.

    3. Or, use a MultiBinding in conjunction with a IMultiValueConverter to bind the Background property directly to Text1 and Text2. The converter would get two strings as input and return a Brush.

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

Sidebar

Related Questions

I have a UserControl that takes a class object as property DataSource. On DataBind,
I have a usercontrol that has several public properties. These properties automatically show up
I have a UserControl that consists of three TextBoxes. On a form I can
I have a usercontrol that is meant to take up the entire form. I
I have a UserControl that has a BaseClass object as a public member. Right
I have a UserControl that I want to add at runtime to my current
I have a usercontrol that hides a div when a button is clicked. <asp:LinkButton
I have a UserControl that is part of my application, I am rendering it
I have created a UserControl that has a ListView in it. The ListView is
I have created a UserControl that has 3 panels. What I what to do

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.