There is a listBox named as listB_addRemove
. I tried to bind a textbox to that listBox but I failed and nothing has shown in textbox. Below is what I tried:
<TextBox Height="23" HorizontalAlignment="Left" Margin="71,40,0,0" Name="textBox1"
VerticalAlignment="Top" Width="120" Grid.Row="1"
DataContext="{Binding ElementName=listB_addRemove, Path=SelectedItem}" />
Where is the problem?
Bind the Text, not the DataContext
:
<TextBox Height="23" HorizontalAlignment="Left" Margin="71,40,0,0" Name="textBox1"
VerticalAlignment="Top" Width="120" Grid.Row="1"
Text="{Binding ElementName=listB_addRemove, Path=SelectedItem}" />
You are not binding the Text
, look up how the DataContext
works. If you keep this you need to add Text="{Binding .}"
. Also note that if you do not bind via Path
directly in the Text
you cannot bind two-way, so if you want that you should move the DataContext
binding to Text
.
您的绑定位于TextBox的DataContext属性上,而应位于Text属性上。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.