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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:15:10+00:00 2026-06-10T09:15:10+00:00

I have two controls contained within a data template. Control #1 is a TextBlock

  • 0

I have two controls contained within a data template. Control #1 is a TextBlock known as “TXTBLOCK”. Control #2 is a TextBox known as “TXTBOX”:

TXTBLOCK has Visibility set to TextBox Visibility using the converter to give the opposite value.

Example:

<TextBlock Name="TXTBLOCK" Visibility="{Binding ElementName=**TXTBOX**, Path=Visibility, Converter={StaticResource toggleVisConverter}}" />

<TextBox Name="TXTBOX" Visibility="{Binding ElementName=**TXTBLOCK**, Path=Visibility, Converter={StaticResource toggleVisConverter}}" />

Converter is:

        if (targetType == typeof(Visibility))
        {
            Visibility vis = (Visibility)value;
            if (vis == Visibility.Collapsed)
            {
                return Visibility.Visible;
            }
            else
            {
                return Visibility.Collapsed;
            }
            //var vis == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed;
        }

        //return vis;
        throw new InvalidOperationException("Value must be of type 'Visibility'.");

Now…to me this should be simple. Changing the visibility of one will set the other’s visibility to false.

Not the case…

Works the very first time through and then the converter stops being called.

Even if I explicitly state: “TXTBOX.Visibility = Visibility.Hidden” in code behind, the converter never gets called.

What gives? What am I missing?

This is my first post on SO…so forgive me if I missed something or need to provide more info. I’ll be happy to do it

Thanks!

  • 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-10T09:15:12+00:00Added an answer on June 10, 2026 at 9:15 am

    It seems WPF has ways of detecting and avoiding stack overflows in data-binding. I’m aware of one, and it seems you’ve found another.

    When you change the visibility of one of your controls, something like the following happens (in theory, at least):

    • You change the visibility of the TextBlock (say),
    • This causes a change in the visibility of the TextBox,
    • This then causes another change in the visibility of the TextBlock,
    • This causes another change in the visibility of the TextBlock, using the first binding again,
    • …

    This would go on forever and quite probably cause a stack overflow, if it weren’t for WPF detecting situations such as this automatically. In this case it seems that it stops listening to the bindings you’ve created once it detects it could be heading towards a stack overflow.

    I haven’t run your code, but I suspect that WPF doesn’t inform you about this either. I’m guessing there’s no exceptions, warnings, nor even a debugging line written to the Output window.

    It seems the pair of bindings is the problem here. What I recommend you do is:

    • Make your ValueConverter a two-way converter, by implementing the ConvertBack method. (If all your converter is doing is swapping between Collapsed and Visible, ConvertBack can probably just call Convert.)
    • Make one of the bindings (it doesn’t matter which one) two-way by adding Mode=TwoWay, and remove the other binding. A TwoWay binding will be enough for communication in both directions between your two controls.

    EDIT: my comment about ConvertBack was that you could implement it as follows:

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return Convert(value, targetType, parameter, culture);
    }
    

    This is because all your converter is doing is swapping between Visible and Collapsed, and converting one way is the same as converting back. This comment was essentially an aside; you can of course implement ConvertBack as you wish, but you will need to implement ConvertBack if you are using your converter in a TwoWay binding.

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

Sidebar

Related Questions

I have two controls which are both contained within a user control. Panel location:
I have two user controls, in one of them I have a textbox, i
I have a listbox which has two buttons to control the priority of the
I have a user control in my wp7 application which contains two text boxes
I have two controls whos code are run time rendered as below: ctl00_PlaceHolderMain_SPWebPartManager_g_3c1ba10a_23ec_4ab5_b303_18f8bd7ee7e7_ctl00_gdvItinerary_ctl03_txtTravelDate ctl00_PlaceHolderMain_SPWebPartManager_g_3c1ba10a_23ec_4ab5_b303_18f8bd7ee7e7_ctl00_gdvItinerary_ctl04_txtTravelDate
I have two controls on a page, one is a search entry and submission
In Winforms you can have two controls tied to the same datasource in a
I have two UIDatePicker controls in my app, one configured with UIDatePickerModeDate and one
I have two User Controls already created now I want to use one as
I have created two custom controls. On the basis of features any one of

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.