MainPage.xaml中
<TextBlock Text="{Binding Pathname, Source={StaticResource ViewModel}, Mode=OneWay}" />
Silverlight TextBlock没有绑定到MVVM,我错过了什么?
的App.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;
}
代码隐藏的MainPage
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中显示什么,NAD a,zip。路径名shource正在改变,但是当我在更改时触发INotifyPropertyChanged事件时似乎没有发生任何事情。
我确定我错过了一些非常明显的东西,但我无法弄清楚什么!
+1,我错过了那部分... :) – 2012-07-31 11:31:06
...课程!天才!我知道这是明显的。谢谢,问题解决了... – xhedgepigx 2012-07-31 11:42:45