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