开发者

Why in this case DataBinding doesn't work vice versa?

开发者 https://www.devze.com 2023-03-16 07:07 出处:网络
First one has the desired affect - change text in textbox and the content of the label changes whereas the second one doesn\'t. Why?

First one has the desired affect - change text in textbox and the content of the label changes whereas the second one doesn't. Why?

 <StackPanel>
        <Label Name="displayText" Content="{Binding ElementName=displayText, 开发者_Go百科Path=Content, Mode=TwoWay}"/>
        <TextBox Name="sourceInfo"/>
    </StackPanel>

<StackPanel>
        <Label Name="displayText"/>
        <TextBox Name="sourceInfo" Text="{Binding ElementName=displayText, Path=Content, Mode=TwoWay}"/>
    </StackPanel>


These two work:

  <StackPanel>
     <Label Name="displayText2" 
            Content="{Binding ElementName=sourceInfo2, Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
     <TextBox Name="sourceInfo2"/>
  </StackPanel>

  <StackPanel>
     <Label Name="displayText"/>
     <TextBox Name="sourceInfo" 
              Text="{Binding ElementName=displayText, Path=Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
  </StackPanel>

You need to bind to the correct property on the correct item. In the top case, you bount the label to its own Content property... oops.

0

精彩评论

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

关注公众号