2013-01-05 3 views
0

LongListSelector 컨트롤의 ItemsSource 속성을 업데이트하려고하면 ArgumentNullReference 예외가 발생합니다.LongListSelector의 데이터 바인딩

XAML 코드 :

<phone:LongListSelector x:Name="LongListSelectorMain" Margin="-12,0,0,0" ItemsSource="{Binding Items}" LayoutMode="List"> 
      <phone:LongListSelector.DataContext> 
       <local:MainViewModel/> 
      </phone:LongListSelector.DataContext> 
      <phone:LongListSelector.ItemTemplate> 
       <DataTemplate> 
        <StackPanel Margin="0,0,0,30"> 
         <TextBlock FontSize="25" Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/> 
         <TextBlock FontSize="25" Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
         <TextBlock FontSize="25" Text="{Binding LineThree}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> 
        </StackPanel> 
       </DataTemplate> 
      </phone:LongListSelector.ItemTemplate> 
     </phone:LongListSelector> 

항목 클래스

Public Class ItemViewModel 
Implements INotifyPropertyChanged 
Private _lineOne As String 
''' <summary> 
''' Proprietà ViewModel di esempio: questa proprietà viene utilizzata per visualizzare il relativo valore mediante un'associazione. 
''' </summary> 
''' <returns></returns> 
Public Property LineOne() As String 
    Get 
     Return _lineOne 
    End Get 
    Set(ByVal value As String) 
     If Not value.Equals(_lineOne) Then 
      _lineOne = value 
      NotifyPropertyChanged("LineOne") 
     End If 
    End Set 
End Property 

Private _lineTwo As String 
''' <summary> 
''' Proprietà ViewModel di esempio: questa proprietà viene utilizzata per visualizzare il relativo valore mediante un'associazione. 
''' </summary> 
''' <returns></returns> 
Public Property LineTwo() As String 
    Get 
     Return _lineTwo 
    End Get 
    Set(ByVal value As String) 
     If Not value.Equals(_lineTwo) Then 
      _lineTwo = value 
      NotifyPropertyChanged("LineTwo") 
     End If 
    End Set 
End Property 

Private _Skipass As Skipass 
''' <summary> 
''' Proprietà ViewModel di esempio: questa proprietà viene utilizzata per visualizzare il relativo valore mediante un'associazione. 
''' </summary> 
''' <returns></returns> 
Public Property Skipass() As Skipass 
    Get 
     Return _Skipass 
    End Get 
    Set(ByVal value As Skipass) 
     If Not value.Equals(_Skipass) Then 
      _Skipass = value 
      NotifyPropertyChanged("Skipass") 
     End If 
    End Set 
End Property 

Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged 
Private Sub NotifyPropertyChanged(ByVal propertyName As String) 
    Dim handler As PropertyChangedEventHandler = PropertyChangedEvent 
    If Nothing IsNot handler Then 
     handler(Me, New PropertyChangedEventArgs(propertyName)) 
    End If 
End Sub 

최종 클래스

의 DataContext

012 34,

최종 클래스

당신은 내가 마이크로 소프트가 제공하는 것이 바로 기본 예제를 사용했습니다 ...하지만 난 그 NullReference 받고 있어요 왜 알아낼 수 없습니다 정직하게 볼 수 있듯이.

+0

예외에서 스택 추적을 게시 할 수 있습니까? –

답변

0

ItemsSource가 바인딩하는 리소스를 선언 할 XAML을 게시 할 수 있습니까?

은 당신이 게시하지 않았기 때문에, 추측이지만, 당신은 당신의 null 참조 예외를 야기 다음 자원이 초기화되지 않은 키, ...뿐만 아니라 이름을 공급하는 경우

<UserControl.Resources> 
    <viewModel:FeedsViewModel x:Key="FeedsViewModel" x:Name="FeedsViewModel"/> 
</UserControl.Resources> 
당신은 단지 다음 자동으로 초기화되는 키 ...

<UserControl.Resources> 
    <viewModel:FeedsViewModel x:Key="FeedsViewModel"/> 
</UserControl.Resources> 

를 선언하지만 명심 경우

당신은 오히려 사용자 정의 컨트롤의 속성으로보다, 사용자 정의 컨트롤의 리소스 사전을 통해 참조 할 것 .