2013-10-26 84 views
0

我的大多數綁定工作正常,但只顯示:Test.Models.PersonModel綁定不起作用?

我喜歡綁定到的屬性(「名稱」)在此類中。

在這裏,我結合部分:

<ItemsControl ItemsSource="{Binding Persons}"> 
    <StackPanel Margin="24, 4, 4, 4" 
       Orientation="Horizontal"> 
     <TextBlock FontSize="{StaticResource PhoneFontSizeExtraLarge}" 
        FontFamily="{StaticResource PhoneFontFamilyLight}" 
        Text="{Binding Name}" 
        VerticalAlignment="Center"/> 
    </StackPanel> 
</ItemsControl> 

人員是類型PersonModel的OberservableCollection。在這裏,PersonModel的代碼:

public class PersonModel : INotifyPropertyChanged 
{ 
    private string _name = null; 

    public string Name 
    { 
     get { return _name; } 
     set { _name = value; NotifyPropertyChanged("Name"); } 
    } 
    private BitmapImage _profilpicture = null; 

    public BitmapImage ProfilPicture 
    { 
     get { return _profilpicture; } 
     set { _profilpicture = value; NotifyPropertyChanged("ProfilPicture"); } 
    } 

    #region PropertyChanged 
    public event PropertyChangedEventHandler PropertyChanged; 
    private void NotifyPropertyChanged(String propertyName) 
    { 
     PropertyChangedEventHandler handler = PropertyChanged; 
     if (null != handler) 
     { 
      handler(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
    #endregion 
} 
+0

你能張貼'PersonModel'類相關的代碼? –

回答

0

您應該使用ItemTemplatemsdn):

<ItemsControl ItemsSource="{Binding Persons}"> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Margin="24, 4, 4, 4" 
         Orientation="Horizontal"> 
       <TextBlock FontSize="{StaticResource PhoneFontSizeExtraLarge}" 
          FontFamily="{StaticResource PhoneFontFamilyLight}" 
          Text="{Binding Name}" 
          VerticalAlignment="Center"/> 
      </StackPanel> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 
+0

感謝它的工作:) – Michael