textbox 默认的绑定方式好像是双向的   当然 你也可以  手动设置   mode=twoway  就OK了

解决方案 »

  1.   

    完全可以,注意你的Book类要实现INotifyPropertyChanged接口,这个是保证你的source变了,target获取消息,然后在UI上,Binding的Mode设置成TwoWay,UpdateSourceTrigger设成PropertyChanged或者LostFocus。
      

  2.   

    高人,为啥我换成Button,Text就没有变化
    我希望点击button,Text能够自动发生变化,但是为啥没反应    public class Test : INotifyPropertyChanged
        {         string   _Text = "Begin";
       
            public string Text
            {
                get{return _Text;}
                protected set { _Text = value; }
            }
            public void Start()
            {
                Text = "Begin";
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(Text));
            }
            public void End()
            {
                Text = "End";
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(Text));
            }
            public event PropertyChangedEventHandler PropertyChanged;
        }
            Test ttt = new Test();        private void button1_Click(object sender, RoutedEventArgs e)
            {
                if (ttt.Text == "Begin")
                    ttt.End();
                else
                    ttt.Start();
            }<Window x:Class="test3.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:test3"
            Title="MainWindow" Height="350" Width="525" >
        <Window.DataContext>
            <ObjectDataProvider x:Name="mt"
          ObjectType="{x:Type local:Test}"    
          />
        </Window.DataContext>    <Grid>
            <Button Content="{Binding ElementName=mt, Path=Text,UpdateSourceTrigger=PropertyChanged}" Height="23" HorizontalAlignment="Left" Margin="121,69,0,0" Name="button1" VerticalAlignment="Top" Width="75" DataContext="{Binding}" Click="button1_Click" />
        </Grid>
    </Window>
      

  3.   

    大哥,你绑错东西啦,你实际绑定的东西是ObjectDataProvider实例化的Test,也就是mt,但你的event handler处理的东西是ttt,就是你自己在code behind里实例化的东西,2个东西根本没关系,你怎么让他变化啊?
      

  4.   


    这样子啊那要是我想绑定自己的对象ttt,该如何弄呢?谢谢回帖!