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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:53:51+00:00 2026-05-23T16:53:51+00:00

Ive got a test code setup with the custom control: /// <summary> /// Interaction

  • 0

Ive got a test code setup with the custom control:

/// <summary>
    /// Interaction logic for UCTest.xaml
    /// </summary>
    public partial class UCTest : UserControl
    {
        public static readonly DependencyProperty LastNameProperty =
       DependencyProperty.Register("LastName", typeof(string), typeof(UCTest),
      new PropertyMetadata("No Name", LastNameChangedCallback, LastNameCoerceCallback),
      LastNameValidateCallback);

        private static void LastNameChangedCallback(
             DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            Console.WriteLine(e.OldValue + " " + e.NewValue);
        }

        private static object LastNameCoerceCallback(DependencyObject obj, object o)
        {
            string s = o as string;
            if (s.Length > 8)
                s = s.Substring(0, 8);
            return s;
        }

        private static bool LastNameValidateCallback(object value)
        {
            return value != null;
        }


        public string LastName
        {
            get
            {
                return (string)GetValue(LastNameProperty);
            }
            set
            {
                SetValue(LastNameProperty, value);
            }
        }


        public UCTest()
        {
            InitializeComponent();
        }
    }

Nothing fancy in the XAML code:

<UserControl ...>
    <Grid DataContext="{Binding}">

    </Grid>
</UserControl>

Code in my View-Model:

public class ViewModel : DependencyObject
    {
        public static readonly DependencyProperty LastNameProperty =
              DependencyProperty.Register("LastName", typeof(string), typeof(ViewModel));

        public string LastName
        {
            get
            {
                return (string)GetValue(LastNameProperty);
            }
            set
            {
                SetValue(LastNameProperty, value);
            }
        }
     }

Code in MainWondow.XAML.cs:

public MainWindow()
        {
            InitializeComponent();

            var viewModel = new ViewModel();
            DataContext = viewModel;

            viewModel.LastName = "asdf";

            viewModel.LastName = "56udfh";

            viewModel.LastName = "09ualkja";

        }

MainWindow.XAML code:

<Window...>
    <Grid>
        <CustomControlTest:UCTest LastName="{Binding LastName}"/>
    </Grid>
</Window>

Ive got breakpoints setup and set to “When Hit”. Output (below) shows that property only called to be updated on the last execution of “LastName”. I would expect it to be calling the on changed on every execute… Any ideas why?

Step into: Stepping over non-user code 'CustomControlTest.App.App'
Step into: Stepping over non-user code 'CustomControlTest.App.InitializeComponent'
Function: CustomControlTest.UCTest.LastNameValidateCallback(object), Thread: 0x1DDC Main Thread
Function: CustomControlTest.UCTest.LastNameValidateCallback(object), Thread: 0x1DDC Main Thread
Function: CustomControlTest.UCTest.LastNameValidateCallback(object), Thread: 0x1DDC Main Thread
Function: CustomControlTest.UCTest.LastNameCoerceCallback(System.Windows.DependencyObject, object), Thread: 0x1DDC Main Thread
Function: CustomControlTest.UCTest.LastNameValidateCallback(object), Thread: 0x1DDC Main Thread
Function: CustomControlTest.UCTest.LastNameValidateCallback(object), Thread: 0x1DDC Main Thread
Function: CustomControlTest.UCTest.LastNameCoerceCallback(System.Windows.DependencyObject, object), Thread: 0x1DDC Main Thread
Function: CustomControlTest.UCTest.LastNameChangedCallback(System.Windows.DependencyObject, System.Windows.DependencyPropertyChangedEventArgs), Thread: 0x1DDC Main Thread
No Name 09ualkja

Thanks,

PS, this is a follow up question to my previous post. Thought Id start a new one because the real issue is not related to my original post. : )

  • 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-23T16:53:51+00:00Added an answer on May 23, 2026 at 4:53 pm

    Your control is not loaded in the MainWindow constructor, so the Binding is not established yet. You may check this by setting breakpoint on the last assignment, in the change handler, and at the end of constructor. You’ll see that constructor finishes until UCTest’s property changes.

    You can solve this problem by deferring assignments using Dispatcher:

    this.Dispatcher.BeginInvoke((Action)(() =>
    {
        viewModel.LastName = "asdf";
    
        viewModel.LastName = "56udfh";
    
        viewModel.LastName = "09ualkja";
    }),
    DispatcherPriority.DataBind);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a class somewhat like this: public class Test { private final List<ISomeType>
I've got the following UL's setup: <ul class=parent> <li> <ul class=child> <li> test </li>
I've got unit test with this code: Excel.Application objExcel = new Excel.Application(); Excel.Workbook objWorkbook
I've got a test class in a module that extends another test class in
I've got a simple test app with a custom view (set up in Interface
I've got to test a message-routing application, whose functionality is broadly as follows: -
I'm writing some test cases, and I've got a test case that is using
I've got a file (test.txt) which contains 1234567. However when I try to read
I've got main folder: c:\test And there I have 2 folders: Movies and Photos.
I've got a fstream my_file(test.txt), but I don't know if test.txt exists. In case

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.