locked
Binding in code not working

    Question

  • Hello,

    xaml:

       

    <GridBackground="{ThemeResourceApplicationPageBackgroundThemeBrush}">


    <TextBoxx:Name="tx01A"HorizontalAlignment="Left"Margin="805,120,0,0"TextWrapping="Wrap"Text="TextBox"VerticalAlignment="Top"/>


           

    <TextBoxx:Name="tx02A"HorizontalAlignment="Left"Margin="930,120,0,0"TextWrapping="Wrap"VerticalAlignment="Top"/>


    </Grid>

    c#

            public MainPage()
            {
                this.InitializeComponent();
    
                Binding bd01 = new Binding();
                bd01.Source = tx01;
                bd01.Path = new PropertyPath("Text");
                tx02.SetBinding(TextBox.TextProperty, bd01);
    
            }
    

    This is a simple Binding in code of two textBoxes.

    If you Change the text in tx01 TextBox the Text in tx02-TextBox should be the same.

    If I do the binding in xaml all works fine. (in code in wpf all works fine).

    Binding in Code in Windows runtime does not update the target.

    Thank you for any help.

    Rowe10

    Monday, March 30, 2015 7:49 PM

Answers

  • Hello rowe10,

    The only reason I can think of that this wouldn't work is when you bind to the wrong control. From your code above, it appears you are binding to the wrong control. Notice your XAML has a different name than the code behind for both textboxes.

    I corrected the textbox names and was able to make changes as expected. I wasn't able to reproduce the issue you are reporting.

    Like I mentioned above, you might be binding to the wrong textbox control.

    Hope this works.


    Abdulwahab Suleiman

    • Marked as answer by rowe10 Tuesday, March 31, 2015 7:14 PM
    Monday, March 30, 2015 11:54 PM
    Moderator