В настоящее время я изучаю WPF и пытаюсь проверить некоторую привязку. Здесь я хочу связать заголовок моей вкладки со свойством fileName
в MainWindow.xaml.cs, но он ничего не показывает
Я не вижу ошибок в окне вывода либо DataContext в теге Window
:
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Связывание в xaml:
<TabItem Header="{Binding fileName, Mode=TwoWay}" x:Name="Header_Tab" Height="20" Width="175">
Моя собственность:
protected void NotifyPropertyChanged(string PropertyName)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(PropertyName));
}
...
public string filePath { get; set; }
public string folderPath { get; set; }
public string fileName
{
get
{
return Path.GetFileName(filePath);
}
set
{
if (value != Path.GetFileName(filePath))
{
value = Path.GetFileName(filePath);
NotifyPropertyChanged(fileName);
}
}
}