1
Please Checkout this Pictute爲什麼而更新它了源
public class Person : INotifyPropertyChanged
{
private string name;
// Declare the event
public event PropertyChangedEventHandler PropertyChanged;
public Person()
{
}
public string newPerson(string Value)
{
this.Name = Value;
return "";
}
public Person(string value)
{
this.name = value;
}
public string Name
{
get { return name; }
set
{
name = value;
// Call OnPropertyChanged whenever the property is updated
OnPropertyChanged("Name");
}
}
// Create the OnPropertyChanged method to raise the event
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
不更新文本塊。 XAML:
<Window.Resources>
<local:Person x:Key="NewPerson" Name="shuvo"/>
<ObjectDataProvider x:Key="AddNewPerson" ObjectType="{x:Type local:Person}" MethodName="newPerson">
<ObjectDataProvider.MethodParameters>
<sys:String>yahoo</sys:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<Grid>
<TextBlock Height="23" HorizontalAlignment="Left" Margin="46,57,0,0" Name="textBlock1" Text="{Binding Source={StaticResource NewPerson},Path=Name}" VerticalAlignment="Top" Width="207" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="46,149,0,0" Name="textBox1" VerticalAlignment="Top" Width="234" Text="{Binding Source={StaticResource AddNewPerson}, Path=MethodParameters[0],BindsDirectlyToSource=True,Mode=OneWayToSource,UpdateSourceTrigger=PropertyChanged}" />
</Grid>