WPF Adding textblock on an item and binding it to a textbox?

You can bind one control to another using an ElementName binding: TextBlock Text="{Binding Text, ElementName=TextBoxInPropertiesWindow} but that's probably not what you want in this case, because it sounds like the properties window and the text box will soon be going away and/or being reused to edit other diagram elements You therefore really need to be thinking in terms of binding both the text box and the text block to the underlying data model / viewmodel. In this way, the text box can update the model (which will still remain after the text box is destroyed), and the text block will then update in response to the change in the model.

You can bind one control to another using an ElementName binding: but that's probably not what you want in this case, because it sounds like the properties window and the text box will soon be going away and/or being reused to edit other diagram elements. You therefore really need to be thinking in terms of binding both the text box and the text block to the underlying data model / viewmodel. In this way, the text box can update the model (which will still remain after the text box is destroyed), and the text block will then update in response to the change in the model.

First, thanks for your concern. But I do not know how to do "binding both the text box and the text block to the underlying data model / viewmodel". Can you explain it please?

– David Apr 23 '09 at 15:00 You have some sort of underlying data model of the diagram, say a Diagram object with a collection of Shape objects. Each TextBlock on the UI is bound to a Shape.Text. Now provide a SelectedShape property on the Diagram (or in the view model if that is not appropriate), update that as the selection changes, and bind the TextBox to SelectedShape.Text.

Hope this makes more sense now! – itowlson Apr 23 '09 at 19:09 I've done it. It takes a little bit time but finally it worked.

Thanks for your help again. – David Apr 25 '09 at 20:28.

Bind the selected shape's datacontext to a property on the window or controller called SelectedItem, then bind the property window's datacontext to SelectedItem.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions