开发者

WPF: bind textblock to textbox

开发者 https://www.devze.com 2023-02-18 04:38 出处:网络
I\'ve one window, with textbox control. this window rise second window in which i have some textbl开发者_JAVA技巧ock

I've one window, with textbox control. this window rise second window in which i have some textbl开发者_JAVA技巧ock

i would like to bind this textblock to the textbox, in order to see what i've typed...

how can i do it ?

thanks


class Window1
{
    void OpenSecondWindow()
    {
        var window = new Window2();
        window.SetTextboxContext(textbox);
        window.Show();
    }
}

class Window2
{
    public void SetTextboxContext(object context)
    {
        textblock.DataContext = context;
    }
}

XAML:

Window1:

<Window>
    <TextBox x:Name="textbox" />
</Window>

Window2:

<Window>
    <TextBlock x:Name="textblock" Text="{Binding Text}" />
</Window>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号