我想将属性FilePath
从类SExcelFile
绑定到textblox。这是我的文件结构。
我的MainWindow.xaml
内部只是一个textblox。
<TextBox Text="{Binding FilePath}" Grid.ColumnSpan="2" Grid.Row="3" Margin="5" Padding="5"/>
MainWindow.xaml.cs
public partial class MainWindow : Window
{
public SManagerRoot ManagerRoot = new SManagerRoot();
public MainWindow()
{
InitializeComponent();
this.DataContext = this.ManagerRoot.ExcelFileManager.ExcelFile;
}
}
SManagerRoot.cs
public class SManagerRoot
{
#region Properties
public SExcelFileManager ExcelFileManager = new SExcelFileManager();
#endregion Properties
}
SExcelFileManager.cs
public class SExcelFileManager
{
#region Properties
public SExcelFile ExcelFile { get; set; }
public SPersonManager PersonManager = new SPersonManager();
#endregion Properties
}
SExcelFile.cs
public class SExcelFile : INotifyPropertyChanged
{
#region Properties
private string _filePath;
public string FilePath
{
set { this._filePath = value; OnPropertyChanged("FilePath"); }
get { return this._filePath; }
}
#endregion Properties
#region c'tor
public SExcelFile()
{
}
public SExcelFile(string filePath)
{
this.FilePath = filePath;
}
#endregion c'tor
#region PropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(name));
}
#endregion PropertyChanged
}
我添加了一个datacontext。 Binding是属性FilePath,当值更改时调用onpropertychanged
。问题在哪里?