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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:36:20+00:00 2026-05-12T09:36:20+00:00

I have a user control that has a textbox. I have tried to expose

  • 0

I have a user control that has a textbox. I have tried to expose the texbox’s Text property by implementing a DependencyProperty with the same name in the UserControl. Thus:

public static readonly DependencyProperty TextProperty =
   DependencyProperty.Register("Text",
                                typeof(string),
                                typeof(UserControlWithTextBox),
                                new UIPropertyMetadata(string.Empty));
    public string Text
    {
        get { return (string)GetValue(TextProperty); }
        set 
        {
            SetValue(TextProperty, value);
            textBox.Text = value;
        }
    }

The get part seems to work OK in my application. However, I tried to bind the IsEnabled property of a button to the Text property of two of these UserControls using a converter that will check if both UserControls’ Text properties are empty strings. I get the following error when the application window loads:

System.InvalidCastException was unhandled
Message=”Cannot convert an object of type MS.Internal.NamedObject to type System.String.”

The Convert method looks thus:

  public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        return (string) values[0] != string.Empty &&
               (string) values[1] != string.Empty;
    }

values[0] and values[1] both have the value DependencyProperty.UnsetValue when the exception is thrown.

Where have I gone wrong?

  • 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-12T09:36:20+00:00Added an answer on May 12, 2026 at 9:36 am

    Judging by your Exception values[0] and values[1] are not String so when you try to explicitly cast them it breaks.

    To avoid these types of things you should really bind your TextBoxes to public properties then bind your buttons IsEnabled to another public property that in the getter will check if the TextBoxes are empty by checking the properties they are bound to.

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

Sidebar

Related Questions

I have a user control that is pretty basic. It contains several TextBox controls,
I want to have a User Control that takes a collection of People (property
I have a UserControl in my Asp.net project that has a public property. I
I have a user control that I'm building. It's purpose is to display the
i have a user control that descends from UserControl. When dropped onto the form
I currently have a user control that is used on both an /Address/Edit and
i'm trying to learn about user controls. I created a user control that has
I have a webpage that requires login. Once a user has logged in I
How do I expose a style as a property in a WPF USER CONTROL
I have a user control on a page of a website that generates a

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.