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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:15:53+00:00 2026-05-21T10:15:53+00:00

I have a custom DepenencyProperty which determines a UserControl’s visibility. It is usually bound

  • 0

I have a custom DepenencyProperty which determines a UserControl’s visibility. It is usually bound to a boolean value, however I would like to set it False when the Escape key is hit.

The problem is, I don’t want to overwrite the binding, I want to update the bindings source value. How can I do this in code behind?

For example, with this XAML

<local:MyControl IsVisibile="{Binding IsControlVisible}" />

I want to update the value of IsControlVisible to false, not MyControl.IsVisible

  • 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-21T10:15:54+00:00Added an answer on May 21, 2026 at 10:15 am

    This should be possible via BindingExpressions, try something like this:

    private void MyControl_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Escape)
        {
            var source = sender as FrameworkElement;
            var expression = source.GetBindingExpression(UIElement.IsVisibleProperty);
            (expression.DataItem as MyDataItem).IsControlVisible = false;
        }
    }
    

    (If you do not reuse the UIElement.IsVisibleProperty you need to specify it via MyControl.IsVisibleProperty of course)


    Here is a reflection-using method:

    var source = sender as FrameworkElement;
    var expression = source.GetBindingExpression(UIElement.IsVisibleProperty);
    var dataType = expression.DataItem.GetType();
    dataType.GetProperties().Single(x => x.Name == expression.ParentBinding.Path.Path)
            .SetValue(expression.DataItem, false, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom UserControl which has a DependencyProperty ItemTemplate of type DataTemplate. I
I have a custom UserControl with an image and a label, both of which
I created a custom control which contains an Image control. I'd like to have
I have a custom ClockFace UserControl which has properties to allow colors, font and
Before I start, I have this code inside of a Custom Usercontrol: private DependencyProperty
I have a custom usercontrol with DataContext={Binding RelativeSource={RelativeSource self}} On the code behind i've
I have a custom control in which I created a custom DependencyProperty called TheObject
I have a custom command definition in my project which compiles fine. When I
I have created Custom User Control which contain TextBox and PasswordBox. it is binding
I have a Generic List of objects that I've bound to a custom control.

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.