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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:16:44+00:00 2026-05-11T13:16:44+00:00

For some reason I’m having issues Binding a custom User Control up through my

  • 0

For some reason I’m having issues Binding a custom User Control up through my ViewModel in an MVVM WPF application. The basic control is a Date entry form with three text boxes. I am using the codebehind for the usercontrol to capture the textchange event and so some manipulation. For some reason Adding Binding to the property never triggers.

XAML of user Control:

<UserControl x:Class='MYLibray.DateBox' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' Height='300' Width='800'> <StackPanel>      <Border CornerRadius='10' Height='200' BorderBrush='Gray' Background='Gray'>     <StackPanel Orientation='Horizontal' OpacityMask='{x:Null}' HorizontalAlignment='Center'>     <TextBox Name='txtMonth' Height='100' Width='90' BorderThickness='0,0,0,5' Background='{x:Null}' Text='' FontSize='72' TextChanged='TextChanged'>         <TextBox.BorderBrush>             <LinearGradientBrush EndPoint='0.5,1' StartPoint='0.5,0'>                 <GradientStop Color='#FF000000' Offset='0'/>                 <GradientStop Color='#FF000000' Offset='1'/>             </LinearGradientBrush>         </TextBox.BorderBrush>     </TextBox>             <TextBlock Text='/' FontSize='72' Height='100' Width='50' />             <TextBox x:Name='txtDay' Height='100' Width='90' Background='{x:Null}' BorderThickness='0,0,0,5' VerticalAlignment='Stretch' FontSize='72' TextChanged='TextChanged'>                 <TextBox.BorderBrush>                     <LinearGradientBrush EndPoint='0.5,1' StartPoint='0.5,0'>                         <GradientStop Color='#FF000000' Offset='0'/>                         <GradientStop Color='#FF000000' Offset='1'/>                     </LinearGradientBrush>                 </TextBox.BorderBrush>             </TextBox>             <TextBlock Text='/19' FontSize='72' Height='100' Width='Auto' />             <TextBox x:Name='txtYear' Height='100' Width='90' Background='{x:Null}' BorderThickness='0,0,0,5'  FontSize='72' TextChanged='TextChanged'>                 <TextBox.BorderBrush>                     <LinearGradientBrush EndPoint='0.5,1' StartPoint='0.5,0'>                         <GradientStop Color='#FF000000' Offset='0'/>                         <GradientStop Color='#FF000000' Offset='1'/>                     </LinearGradientBrush>                 </TextBox.BorderBrush>             </TextBox>     </StackPanel>     </Border>  </StackPanel> 

CodeBehind:

public partial class DateBox : UserControl 

{

  private string _date = '';   public static DependencyProperty TextProperty = DependencyProperty.RegisterAttached('DateText', typeof(string), typeof(DateBox), new PropertyMetadata(TextPropertyChanged));   public static DependencyProperty EnabledProperty = DependencyProperty.RegisterAttached('Enabled', typeof(bool), typeof(DateBox), null);    public DateBox()   {                                       InitializeComponent();      this.DataContext = this;      txtMonth.Focus();   }    public bool Enabled   {      get      {         return (bool)GetValue(DateBox.EnabledProperty);      }      set      {         SetValue(DateBox.EnabledProperty, value);          txtDay.IsEnabled = value;         txtMonth.IsEnabled = value;         txtYear.IsEnabled = value;      }   }    public string DateText   {      get      {         return (string)this.GetValue(TextProperty);      }      set      {         this.SetValue(TextProperty, value);      }   }    static void TextPropertyChanged(DependencyObject property,DependencyPropertyChangedEventArgs args)   {      ((DateBox)property).OnTextPropertyChanged((object)args.NewValue);   }    private void OnTextPropertyChanged(object newValue)   {      _date = newValue.ToString();      this.UpdateLayout();      DateTime d;      if (DateTime.TryParse(_date, out d))      {         txtDay.Text = d.Day.ToString();         txtMonth.Text = d.Month.ToString();         txtYear.Text = (d.Year - 1900).ToString();      }      else      {         txtDay.Text = '';         txtMonth.Text = '';         txtYear.Text = '';      }       DateText = d.ToShortDateString();   }    bool AreAllValidNumericChars(string str)   {      bool ret = true;      if (str == System.Globalization.NumberFormatInfo.CurrentInfo.PositiveSign)      {         return ret;      }      int l = str.Length;      for (int i = 0; i < l; i++)      {         char ch = str[i];         ret &= Char.IsDigit(ch);      }       return ret;   }    private void TextChanged(object sender, TextChangedEventArgs e)   {       TextBox txt = (TextBox)sender;       switch (txt.Name)      {         case 'txtMonth':            if (txt.Text.Length == 1)            {               if (Convert.ToInt32(txt.Text) > 1)               {                  string value = txt.Text;                  txt.Text = '0' + value;                  txtDay.Focus();               }            }            if (txt.Text.Length == 2)            {               txtDay.Focus();            }            break;         case 'txtDay':            if (txt.Text.Length == 1)            {               if (Convert.ToInt32(txt.Text) > 3)               {                  string value = txt.Text;                  txt.Text = '0' + value;                  txtYear.Focus();               }            }            if (txt.Text.Length == 2)            {               txtYear.Focus();            }            break;          case 'txtYear':            if (txt.Text.Length == 2)            {               DateTime d;               string datestring = txtMonth.Text + '/' + txtDay.Text + '/19' + txtYear.Text;               if (DateTime.TryParse(datestring,out d))               {                  DateText = d.ToShortDateString();               }            }            break;         default:            break;      }   } 

}

When I create the usercontrol in the DataTemplate like so:

<uc:DateBox DateText='{Binding BirthDate}' /> 

The get and set of BirthDate in my ViewModel never get set. BirthDate on the VM is a String.

  • 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-11T13:16:45+00:00Added an answer on May 11, 2026 at 1:16 pm

    Check the DataContext of the control and of the parent.

    to help with debugging your bindings, check out Bea Stollnitz’s blog

    basically, add this xmlns to your control

    xmlns:diagnostics='clr-namespace:System.Diagnostics;assembly=WindowsBase' 

    then add this to your Binding(s)

    {Binding ....    , diagnostics:PresentationTraceSources.TraceLevel=High } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The value can be retrieved from the DropDownList, because the… May 11, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer Well the first issue to keep in mind is that… May 11, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer I would segment part of the page to use for… May 11, 2026 at 11:34 pm

Related Questions

For some reason I never see this done. Is there a reason why not?
For some reason I am having troubles with a DBI handle. Basically what happened
For some reason I can't find a way to get the equivalents of sqlite's
For some reason I'm not getting this. (Example model below) If I write: var
For some reason I can't use runat=server as an attribute for the input tag

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.