I run in a trouble. WPF, compiled XAML: on changed text handler run but not all controls initizlzed

Roma Golich 20 Reputation points
2025-01-19T05:49:16.4366667+00:00

Clipboard_01-19-2025_01_-_Copy_XAML_eventHandlers_wrk_before_all_ctrl_has_been_initialized_vs9_vs17_tested

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,819 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
830 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 119.2K Reputation points
    2025-01-20T00:19:52.2866667+00:00

    Try this:

    private void textBox1_TextChanged( object sender, TextChangedEventArgs e )
    {
        if( !IsLoaded ) return;
    
        Debug.Assert( textBox2 != null );
        textBox2.Text = textBox1.Text;
    }
    

    If required, handle the Loaded event of window too:

    private void Window_Loaded( object sender, RoutedEventArgs e )
    {
        textBox2.Text = textBox1.Text;
    }
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.