我是新來的WPF,我試圖綁定一個dependacy屬性。 我想的是,我寫上WPFCtrl文字:FilterTextBox將在TextBlock中無法綁定WPF DependencyProperty
在這裏displaied是我的XAML
xmlns:WPFCtrl="clr-namespace:WPFControls"
xmlns:local="clr-namespace:WpfApplication9"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:Person x:Key="myDataSource" />
</Window.Resources>
<Grid>
<StackPanel>
<StackPanel.DataContext>
<Binding Source="{StaticResource myDataSource}"/>
</StackPanel.DataContext>
<WPFCtrl:FilterTextBox Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged }"/>
<TextBlock Width="55" Height="25" Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
</Grid>
這裏的人類
namespace WpfApplication9
{
public class Person : INotifyPropertyChanged
{
private string name = "";
// Declare the event
public event PropertyChangedEventHandler PropertyChanged;
public Person()
{
}
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));
}
}
}
}
和FilterTextBox文本屬性
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(FilterTextBox), new PropertyMetadata());
public string Text
{
//get { return _tbFilterTextBox.Text == null ? null : _tbFilterTextBox.Text.TrimEnd(); }
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
//set { _tbFilterTextBox.Text = value; }
}
問題是它沒有進入OnP ropertyChanged() 我在做什麼錯?