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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:18:55+00:00 2026-05-10T19:18:55+00:00

I am attempting to bind a WPF textbox’s Maxlength property to a known constant

  • 0

I am attempting to bind a WPF textbox’s Maxlength property to a known constant deep within a class. I am using c#.

The class has a structure not too dissimilar to the following:

namespace Blah {     public partial class One     {         public partial class Two         {              public string MyBindingValue { get; set; }               public static class MetaData              {                  public static class Sizes                  {                      public const int Length1 = 10;                      public const int Length2 = 20;                  }              }         }     } } 

Yes it is deeply nested, but unfortunately in this instance I can’t move things round very much without huge rewrites required.

I was hoping I’d be able to bind the textbox MaxLength to the Length1 or Length2 values but I can’t get it to work.

I was expecting the binding to be something like the following:

<Textbox Text='{Binding Path=MyBindingValue}' MaxLength='{Binding Path=Blah.One.Two.MetaData.Sizes.Length1}' /> 

Any help is appreciated.

Many 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. 2026-05-10T19:18:55+00:00Added an answer on May 10, 2026 at 7:18 pm

    Fixed!

    Initially I tried doing this:

    {Binding Path=MetaData+Sizes.Length1} 

    which compiled ok, however the binding failed at runtime, despite the Class ‘Two’ being the datacontext the path couldn’t resolve into the inner static classes (could I have done something like : {Binding Path={x:Static MetaData+Size.Length1}} ?)

    I had to fiddle with the layout of my classes a little but the binding is now working.

    New class structure:

    namespace Blah {     public static class One     {         // This metadata class is moved outside of class 'Two', but in this instance         // this doesn't matter as it relates to class 'One' more specifically than class 'Two'         public static class MetaData         {             public static class Sizes             {                 public static int Length1 { get { return 10; } }                 public static int Length2 { get { return 20; } }             }         }          public partial class Two         {             public string MyBindingValue { get; set; }         }     } } 

    Then my binding statement is as follows:

    xmlns:local='clr-namespace:Blah' 

    and

    MaxLength='{x:Static local:MetaData+Sizes.Length1}' 

    Which appears to work ok. I’m not sure whether or not the constants needed to be converted into properties, but there doesn’t appear to be any harm in doing so.

    Thankyou everyone for your help!

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

Sidebar

Related Questions

Using WPF and Prism. I have a view, containing 1 textblock <UserControl x:Class=ArmoryModule.Views.ResultsView xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
I am attempting to implement a WPF ViewModel using Castle Windsor Dynamic Proxies. The
I am attempting to bind my ViewModel's IsInInputMode property to a Dependency Property in
I am currently using Backbone.js collection and View and I am attempting to bind
Using LDAP is checking a username/password as simple as attempting to bind as that
I'm attempting to bind a DependancyProperty in one of my usercontrols to the Width
I am attempting to bind a ListView control to a DataTable , but the
I've got a Windows Forms control that I'm attempting to wrap as a WPF
Attempting to set up Samba + OpenLDAP using nss_ldap. After joining Windows7 to Samba
Greetings, I'm using WPF with a Model-View-ViewModel pattern, and I have a view model

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.