开发者

How to confirm what properties are being bound to in XAML?

I've got a "MainModelView" which implements INotifyPropertyChanged and has a property that exposes an ObservableCollection<T> called ExposedCollection. In our MainPage.xaml, we have a ListBox whose ItemsSource is supposed to be bound to MainModelView.ExposedCollection.

The MainModelView makes a REST call to populate the ExposedCollection in the background. When WebClient is done doing its thing, the ASyncCallback calls NotifyPropertyCHanged which checks if the PropertyChanged event is null, and if not raises it. Pretty basic stuff

Problem is, ListBox never seems to bind to ExposedCollection. I set a breakpoint on our null check for NotifyPropertyChanged, and there are never any listeners on PropertyChanged.

I've tried instantiating MainViewModel in PhoneApplicationPage.Resources, in PhoneApplicationPage.DataContext and the PhoneApplicationFrame.DataContext in App.xaml. In all cases the PropertyChanged event is still null. What am I missing here?

<phone:PhoneApplicationPage.DataContext>
    <gmvm:MainViewModel x:Name="MainViewModel" />
</phone:PhoneApplicationPage.DataContext>
...
<ListBox x:Name="MyListBox" ItemsSource="{Binding ExposedCollection}" Margin="0,20,-12,0"开发者_JAVA百科>
.....
</Listbox>  


You should check the Output window in Visual Studio to see if there are any binding errors when running your app.


I'm not sure if it makes a difference, but have you tried implementing ExposedCollection as a Dependency Property? If you do that, it might eliminate the need for implementing the INotifyPropertyChanged interface and help with the binding to the listbox? Crazier things have worked for me...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜