主页.xaml
<TextBlock Text="{Binding Pathname, Source={StaticResource ViewModel}, Mode=OneWay}" />
应用程序.xaml
<ResourceDictionary>
<vm:InspectViewModel x:Key="ViewModel" />
</ResourceDictionary>
视图模型
private string _pathname = null;
public string Pathname
{
get { return _pathname; }
set
{
if (_pathname != value)
{
_pathname = value;
RaisePropertyChanged("Pathname");
}
}
}
public void UpdatePathname(string path)
{
Pathname = path;
}
主页代码隐藏
private void lazyNavTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
InspectViewModel vm = new InspectViewModel();
var path = view.GetPath().ToArray();
string pathname = null;
// to figure out what the pathname is
for (int i = 0; i < path.Count(); i++)
{
TreeList treeItem = (TreeList)path[i].Key;
if (i == path.Count()-1)
pathname = pathname + treeItem.Name;
else
pathname = pathname + treeItem.Name + " : ";
}
vm.UpdatePathname(pathname);
}
绑定的 TextBlock 什么都不显示,nada,zip。路径名 shource 正在正确更改,但是当我在更改时触发 INotifyPropertyChanged 事件时似乎没有发生任何事情。
我确定我错过了一些非常明显的东西,但我不知道是什么!