请教WPF数据绑定的问题 textbox 默认的绑定方式好像是双向的 当然 你也可以 手动设置 mode=twoway 就OK了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 完全可以,注意你的Book类要实现INotifyPropertyChanged接口,这个是保证你的source变了,target获取消息,然后在UI上,Binding的Mode设置成TwoWay,UpdateSourceTrigger设成PropertyChanged或者LostFocus。 高人,为啥我换成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> 大哥,你绑错东西啦,你实际绑定的东西是ObjectDataProvider实例化的Test,也就是mt,但你的event handler处理的东西是ttt,就是你自己在code behind里实例化的东西,2个东西根本没关系,你怎么让他变化啊? 这样子啊那要是我想绑定自己的对象ttt,该如何弄呢?谢谢回帖! 求带SQL数据库的winform安装部署教程 vs 中 没法像eclipse编写java那样 可以有重载、覆盖?? ADO.NET 调用 Sybase 数据库 出现的问题。懂的人帮忙看看 将C++中函数导入到C#中遇到的问题 基础转换问题 请高手指教 做一个全局的捕获异常的函数 怎么没人回答啊?高手安在?急煞老弟了! 如何给外部程序指定打开坐标 请教各位大侠 请教:在OpenFileDialog读取图片文件的同时如何预览图片. 如何移動繪所繪制之圖形並改變屬性~請各位高手幫忙 C#的视频代码
我希望点击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>
这样子啊那要是我想绑定自己的对象ttt,该如何弄呢?谢谢回帖!