First of all, I used objectdataproviding, but this is not a "ttt" object, these are two different things.
Secondly, PropertyChanged(this,new PropertyChangedEventArgs("Text"));“Text” is a name not a variable.
So, the following code may be useful to others.
Data class:
namespace test3
{
public class Test : INotifyPropertyChanged
{
string _Text = "Begin";
public string Text
{
get{return _Text;}
protected set { _Text = value;
NotifyPropertyChanged("Text");
}
}
public void Start()
{
Text = "Begin";
}
public void End()
{
Text = "End";
}
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
Logical cs:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
button1.DataContext=ttt;
}
Test ttt = new Test();
private void button1_Click(object sender, RoutedEventArgs e)
{
if (ttt.Text == "Begin")
ttt.End();
else
ttt.Start();
}
}
}
xaml:
<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" >
<Grid>
<Button Content="{Binding Path=Text,UpdateSourceTrigger=PropertyChanged}" Height="23" HorizontalAlignment="Left" Margin="121,69,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</Grid>
</Window>
source
share