数据绑定
1、TextBox与Slider数据双向绑定
<TextBox HorizontalAlignment="Left" Margin="155,154,0,0" TextWrapping="Wrap" Text="{Binding Value,Mode=TwoWay,ElementName=slider1}" VerticalAlignment="Top" Height="38" Width="217"/>
<Slider x:Name="slider1" HorizontalAlignment="Left" Margin="155,245,0,0" Minimum="0" Maximum="100" VerticalAlignment="Top" Width="344"/>
public class person : INotifyPropertyChanged
{
private string _name;
public string Name
{
get { return _name; }
set
{
_name = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
}
}
}
private string _age;
public string Age
{
get { return _age; }
set
{
_age = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Name"));
}
}
}
//
public event PropertyChangedEventHandler PropertyChanged;
}